base-routes
Advanced tools
Comparing version 0.2.2 to 1.0.0
63
index.js
'use strict'; | ||
var debug = require('debug')('base:routes'); | ||
var rethrow = require('template-error'); | ||
var router = require('en-route'); | ||
var utils = require('./utils'); | ||
@@ -11,4 +13,4 @@ | ||
/** | ||
* The `Router` and `Route` classes are on the instance, in case they need | ||
* to be accessed directly. | ||
* The `Router` and `Route` classes are on the `app` instance, | ||
* in case they need to be accessed directly. | ||
* | ||
@@ -22,8 +24,8 @@ * ```js | ||
this.define('Router', utils.router.Router); | ||
this.define('Route', utils.router.Route); | ||
this.define('Router', router.Router); | ||
this.define('Route', router.Route); | ||
/** | ||
* Lazily initalize `router`, to allow options and custom methods to be | ||
* define after instantiation. | ||
* Lazily initalize `router`, to allow options and | ||
* custom methods to be defined after instantiation. | ||
*/ | ||
@@ -44,11 +46,11 @@ | ||
/** | ||
* Handle a middleware `method` for `file`. | ||
* Handle middleware `method` for the given `file`. | ||
* | ||
* ```js | ||
* app.handle('customMethod', file, callback); | ||
* app.handle('methodName', file, next); | ||
* ``` | ||
* @name .handle | ||
* @param {String} `method` Name of the router method to handle. See [router methods](./docs/router.md) | ||
* @param {String} `methodName` Name of the router method to handle. | ||
* @param {Object} `file` View object | ||
* @param {Function} `callback` Callback function | ||
* @param {Function} `next` Callback function | ||
* @return {undefined} | ||
@@ -60,2 +62,3 @@ * @api public | ||
debug('handling "%s" middleware for "%s"', method, file.basename); | ||
this.lazyRouter(); | ||
@@ -70,4 +73,2 @@ if (typeof next !== 'function') { | ||
this.lazyRouter(); | ||
file.options = file.options || {}; | ||
@@ -101,6 +102,8 @@ if (!file.options.handled) { | ||
/** | ||
* Run the given middleware handler only if the file has not already been handled | ||
* by `method`. | ||
* Run the given middleware handler only if the file has not | ||
* already been handled by `method`. | ||
* | ||
* ```js | ||
* app.handleOnce(method, file, callback); | ||
* // example | ||
* app.handleOnce('onLoad', file, callback); | ||
@@ -116,13 +119,6 @@ * ``` | ||
this.define('handleOnce', function(method, file, cb) { | ||
if (typeof cb !== 'function') { | ||
cb = function(err, file) { | ||
app.handleError(method, file, function() { | ||
throw err; | ||
}); | ||
}; | ||
} | ||
if (!file.options.handled) { | ||
file.options.handled = []; | ||
} | ||
if (file.options.handled.indexOf(method) === -1) { | ||
@@ -160,3 +156,3 @@ this.handle(method, file, cb); | ||
try { | ||
utils.rethrow(file.content, file.data); | ||
rethrow(file.content, file.data); | ||
} catch (e) { | ||
@@ -181,5 +177,6 @@ console.log(e); | ||
/** | ||
* Create a new Route for the given path. Each route contains a separate middleware | ||
* stack. See the [route API documentation][route-api] for details on adding handlers | ||
* and middleware to routes. | ||
* Create a new Route for the given path. Each route | ||
* contains a separate middleware stack. See the [en-route][] | ||
* API documentation for details on adding handlers and | ||
* middleware to routes. | ||
* | ||
@@ -208,4 +205,5 @@ * ```js | ||
/** | ||
* Add callback triggers to route parameters, where `name` is the name of | ||
* the parameter and `fn` is the callback function. | ||
* Add callback triggers to route parameters, where | ||
* `name` is the name of the parameter and `fn` is the | ||
* callback function. | ||
* | ||
@@ -237,4 +235,5 @@ * ```js | ||
/** | ||
* Special route method that works just like the `router.METHOD()` | ||
* methods, except that it matches all verbs. | ||
* Special route method that works just like the | ||
* `router.METHOD()` methods, except that it matches | ||
* all verbs. | ||
* | ||
@@ -262,4 +261,4 @@ * ```js | ||
/** | ||
* Add a router handler method to the instance. Interchangeable with | ||
* the [handlers]() method. | ||
* Add a router handler method to the instance. Interchangeable | ||
* with the [handlers]() method. | ||
* | ||
@@ -266,0 +265,0 @@ * ```js |
{ | ||
"name": "base-routes", | ||
"description": "Plugin for adding routes support to your `base` application. Requires templates support to work.", | ||
"version": "0.2.2", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/node-base/base-routes", | ||
@@ -14,4 +14,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"index.js", | ||
"LICENSE", | ||
"README.md", | ||
"utils.js" | ||
@@ -27,13 +25,12 @@ ], | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"en-route": "^0.7.5", | ||
"is-valid-app": "^0.2.0", | ||
"lazy-cache": "^2.0.1", | ||
"debug": "^2.6.8", | ||
"en-route": "^1.0.0", | ||
"is-valid-app": "^0.3.0", | ||
"template-error": "^0.1.2" | ||
}, | ||
"devDependencies": { | ||
"base-app": "^0.2.2", | ||
"gulp-format-md": "^0.1.9", | ||
"mocha": "^2.4.5", | ||
"should": "^8.3.1" | ||
"base-app": "^0.2.6", | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.5.0", | ||
"should": "^11.2.1" | ||
}, | ||
@@ -45,2 +42,3 @@ "keywords": [ | ||
"base", | ||
"base-plugin", | ||
"baseplugin", | ||
@@ -64,6 +62,4 @@ "building-blocks", | ||
"base", | ||
"base-option", | ||
"base-plugins", | ||
"en-route", | ||
"templates" | ||
"gulp-routes" | ||
] | ||
@@ -83,5 +79,6 @@ }, | ||
"reflinks": [ | ||
"verb" | ||
"verb", | ||
"base" | ||
] | ||
} | ||
} |
18
utils.js
'use strict'; | ||
var debug = require('debug')('base:routes'); | ||
var utils = require('lazy-cache')(require); | ||
var fn = require; | ||
require = utils; | ||
var isValidApp = require('is-valid-app'); | ||
var utils = module.exports; | ||
/** | ||
* Lazily required module dependencies | ||
* Returns true if `app` is valid and is not already registered. | ||
*/ | ||
require('en-route', 'router'); | ||
require('is-valid-app'); | ||
require('template-error', 'rethrow'); | ||
require = fn; | ||
utils.isValid = function(app) { | ||
if (!utils.isValidApp(app, 'base-routes', ['app', 'collection', 'views', 'list'])) { | ||
if (!isValidApp(app, 'base-routes', ['app', 'collection', 'views', 'list'])) { | ||
return false; | ||
@@ -33,2 +27,6 @@ } | ||
/** | ||
* Default router methods | ||
*/ | ||
utils.methods = [ | ||
@@ -35,0 +33,0 @@ 'onLoad', |
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17664
4
5
0
0
221
1
307
+ Addedarr-union@3.1.0(transitive)
+ Addedasync-array-reduce@0.2.1(transitive)
+ Addeddefine-property@1.0.0(transitive)
+ Addeden-route@1.0.1(transitive)
+ Addedis-descriptor@1.0.3(transitive)
+ Addedis-valid-app@0.3.0(transitive)
+ Addedis-valid-instance@0.3.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedtypeof-article@0.1.1(transitive)
- Removedlazy-cache@^2.0.1
- Removeden-route@0.7.5(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedis-valid-app@0.2.1(transitive)
- Removedis-valid-instance@0.2.0(transitive)
- Removedlazy-cache@1.0.4(transitive)
Updateddebug@^2.6.8
Updateden-route@^1.0.0
Updatedis-valid-app@^0.3.0