base-routes
Plugin for adding routes support to your base
application. Requires templates support to work.
TOC
Install
Install with npm:
$ npm install base-routes --save
Usage
var routes = require('base-routes');
var Base = require('base-app');
var app = new Base();
app.use(routes());
API
Example
var router = new app.Router();
var route = new app.Route();
Handle a middleware method
for file
.
Params
method
{String}: Name of the router method to handle. See router methodsfile
{Object}: View objectcallback
{Function}: Callback functionreturns
{undefined}
Example
app.handle('customMethod', file, callback);
Run the given middleware handler only if the file has not already been handled by method
.
Params
method
{Object}: The name of the handler method to call.file
{Object}returns
{undefined}
Example
app.handleOnce('onLoad', file, callback);
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.
Params
path
{String}returns
{Object}: Returns the instance for chaining.
Example
app.create('posts');
app.route(/blog/)
.all(function(file, next) {
next();
});
app.post('whatever', {path: 'blog/foo.bar', content: 'bar baz'});
Add callback triggers to route parameters, where name
is the name of the parameter and fn
is the callback function.
Params
name
{String}fn
{Function}returns
{Object}: Returns the instance for chaining.
Example
app.param('title', function(view, next, title) {
next();
});
app.onLoad('/blog/:title', function(view, next) {
next();
});
Special route method that works just like the router.METHOD()
methods, except that it matches all verbs.
Params
path
{String}callback
{Function}returns
{Object} this
: for chaining
Example
app.all(/\.hbs$/, function(view, next) {
next();
});
Add a router handler method to the instance. Interchangeable with the handlers method.
Params
method
{String}: Name of the handler method to define.returns
{Object}: Returns the instance for chaining
Example
app.handler('onFoo');
app.handler(['onFoo', 'onBar']);
Add one or more router handler methods to the instance.
Params
methods
{Array|String}: One or more method names to define.returns
{Object}: Returns the instance for chaining
Example
app.handlers(['onFoo', 'onBar', 'onBaz']);
app.handlers('onFoo');
Related projects
You might also be interested in these projects:
- base-option: Adds a few options methods to base, like
option
, enable
and disable
. See the readme… more | homepage - base-plugins: Upgrade's plugin support in base applications to allow plugins to be called any time after… more | homepage
- base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more | homepage
- templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb, v0.9.0, on May 17, 2016.