Created
March 19, 2014 20:05
-
-
Save doowb/9650061 to your computer and use it in GitHub Desktop.
Example of setting up expected api from environments using helpers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var expects = function(config, spec) { | |
for(var k in spec) { | |
if (config[k] === 'undefined') { | |
config[k] = spec[k]; | |
} | |
} | |
}; | |
var spec = { | |
context: function() { return {}; }, | |
registerHelpers: function() { } | |
}; | |
module.exports = function (config) { | |
expects(config, spec); | |
Library.addHelper('foo', function (bar) { | |
var context = config.context(); | |
var baz = context[bar] || 'default'; | |
return 'Hello ' + baz; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment