Manage context for templates.
npm i context-manager --save
var context = require('context-manager');
Create an instance of Context.
Add a context level, optionally passing a value to start with.
name {String}: The name of the context to add.level {Number}: Numerical value representing the order in which this level should be merged versus other lvl.value {Object}: Optionally pass an object to start with.context.setContext('locals', {a: 'b'});
Get the raw (un-merged) context for name.
name {String}: The context to get.returns: {*}context.setContext('a', {a: 'b'});
context.getContext('a');
// => {a: 'b'}
Extend context name with the given value
name {String}key {String}value {Object}returns: {String}context.setContext('locals', {a: 'b'});
Set the level for a context. This determines the order in which the context will be merged when .calculate() is called.
name {String}: The name of the context.level {Number}: The level (number) to set for the level.if (foo) {
context.setLevel('locals', 10);
} else {
context.setLevel('locals', 0);
}
Calculate the context, optionally passing a callback fn for sorting. (Note that sorting must be done on levels, not on the context names).
keys {String|Array}: Key, or array of keys for context levels to include.fn {Function}: Sort function for determining the order of merging.app.calculate(['a', 'b'], function(a, b) {
return app.lvl[a] - app.lvl[a];
});
Clear all contexts.
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the license
This file was generated by verb on February 21, 2015.