Last active
March 11, 2017 15:11
-
-
Save ozten/0b34b6325159081863e9 to your computer and use it in GitHub Desktop.
Adapter layer for bridging `handlebars-layouts` and `express-handlebars`.
This file contains 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
/** | |
* Adapter layer for bridging `handlebars-layouts` and `express-handlebars`. | |
* | |
* Usage: | |
* var exphbs = require('express-handlebars'); | |
* var handlebarsLayout = require('handlebars-layouts'); | |
* var exphbsAdapter = require('express-handlebars-layouts-adapter'); | |
* | |
* handlebarsLayout(exphbsAdapter); | |
* var exphbs.create({ | |
* helpers: handlebarsLayout(exphbsAdapter()).helpers() | |
* }); | |
* app.engine('handlebars', hbs.engine); | |
* | |
* WUT? | |
* | |
* It is not easy to use `handlebars-layouts` with `express-handlebars`. | |
* | |
* handlebars-layouts API | |
* | |
* layouts(handlebars); // calls handlebars.registerHelper(helpers); | |
* // then returns handlebars | |
* | |
* express-handlebars API | |
* var express = require('express'), | |
* exphbs = require('express-handlebars'); | |
* | |
* var app = express(); | |
* | |
* var hbs = exphbs.create({ | |
* // Specify helpers which are only registered on this instance. | |
* helpers: { | |
* foo: function () { return 'FOO!'; }, | |
* bar: function () { return 'BAR!'; } | |
* } | |
* }); | |
* | |
* app.engine('handlebars', hbs.engine); | |
* app.set('view engine', 'handlebars'); | |
*/ | |
module.exports = function() { | |
var _helpers = {}; | |
return { | |
registerHelper: function registerHelper(helpers) { | |
_helpers = helpers; | |
}, | |
helpers: function() { | |
return _helpers; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment