Package Exports
- en-route
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (en-route) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
en-route 
Routing for static site generators and build systems, heavily based on express.js and kerouac routes.
Install
Install with npm
npm i en-route --save
API
Router
Initialize a new Router
with the given options
.
options
{Object}
var Router = require('en-route');
var router = new Router(options);
.route
Create a route for a filter
that will call a middleware
stack when the filter
is matched.
filter
{Function|String}: Either a string to match on or a function that filters.middleware
{Function|Array}: Middleware stack.returns
: {Object}
// using a filepath as the filter
router.route('/path/to/:filename.md', function (key, value, next) {
// process value
value.content = markdown(value.content);
value.options.ext = '.html'
// use the params from the filepath (:filename)
console.log(this.params.filename);
// done, so call the next middleware
next();
});
// using a function as the filter
router.route(function (key, value) {
// only process files that are not drafts
return (!('drafts' in value.data) || (!value.data.draft && value.data.draft === false));
}, function (key, value, next) {
// process value
// done, so call the next middleware
next();
});
.middleware
Call the dispatcher on on arguments
arguments
{arguments}: Any arguments are passed through the dispatcher. The arguments must match the arguments expected by the filter and middleware.next
{Function}: Callback.returns
: {Object}
var page = {
path: 'some/file/path.md',
data: {
draft: false
},
options: {
ext: '.md'
}
};
router.middleware(page.path, page, function (err) {
if (err) {
// something bad happened
}
// everything is good
});
.middlewareSync
file
{Object}: File object.returns
{Object}: object containing anerr
if an error occurred.
Call the dispatcher on a file
object.
.use
Utilize the given middleware fn
to the given stage
, defaulting to _*_
.
stage
{String}: Stage for when this middleware should be calledfn
{Function}: Additional middleware functions to call during the stagereturns
{Router}: for chaining.
Example:
router.use('init', function (a, b, next) {
a.foo = {};
b.bar = {};
next();
});
Author
Jon Schlinkert
Brian Woodward
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
Based on previous work by:
Copyright (c) 2009-2014 TJ Holowaychuk tj@vision-media.ca Copyright (c) 2012-2013 Jared Hanson http://jaredhanson.net/
This file was generated by verb-cli on October 23, 2014.