base-helpers
Adds support for managing template helpers to your base application.
Install
Install with npm:
$ npm install --save base-helpers
Install with yarn:
$ yarn add base-helpers
Usage
Register the plugin with your base application:
var Base = require('base');
var helpers = require('base-helpers');
base.use(helpers());
API
Register a template helper.
Params
name
{String}: Helper namefn
{Function}: Helper function.
Example
app.helper('upper', function(str) {
return str.toUpperCase();
});
Register multiple template helpers.
Params
helpers
{Object|Array}: Object, array of objects, or glob patterns.
Example
app.helpers({
foo: function() {},
bar: function() {},
baz: function() {}
});
Register an async helper.
Params
name
{String}: Helper name.fn
{Function}: Helper function
Example
app.asyncHelper('upper', function(str, next) {
next(null, str.toUpperCase());
});
Register multiple async template helpers.
Params
helpers
{Object|Array}: Object, array of objects, or glob patterns.
Example
app.asyncHelpers({
foo: function() {},
bar: function() {},
baz: function() {}
});
Get a previously registered helper.
Params
name
{String}: Helper namereturns
{Function}: Returns the registered helper function.
Example
var fn = app.getHelper('foo');
Get a previously registered async helper.
Params
name
{String}: Helper namereturns
{Function}: Returns the registered helper function.
Example
var fn = app.getAsyncHelper('foo');
Return true if sync helper name
is registered.
Params
name
{String}: sync helper namereturns
{Boolean}: Returns true if the sync helper is registered
Example
if (app.hasHelper('foo')) {
}
Return true if async helper name
is registered.
Params
name
{String}: Async helper namereturns
{Boolean}: Returns true if the async helper is registered
Example
if (app.hasAsyncHelper('foo')) {
}
Register a namespaced helper group.
Params
helpers
{Object|Array}: Object, array of objects, or glob patterns.
Example
app.helperGroup('mdu', {
foo: function() {},
bar: function() {},
});
History
v1.0.0
- upgrades dependencies to take advantage of improvements to load-helpers and helper-cache. There shouldn't be any breaking changes here, so if you experience regressions please do not hesitate to create an issue.
v0.2.0
- adds support for passing helper groups as a function. For example, the
log
helper can be a function, but it can also have log.warning
and log.info
functions as properties.
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.5.0, on April 20, 2017.