Skip to content

Commit

Permalink
Update express-hbs to 0.8.4
Browse files Browse the repository at this point in the history
fixes #4364, refs #4439, refs #4799

- Update express-hbs to 0.8.5
- Use preventIndent option onCompile
- Update registerAsyncHelper to support passing through options when needed
  • Loading branch information
ErisDS committed Mar 10, 2015
1 parent 6bb073c commit 4b05585
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
13 changes: 9 additions & 4 deletions core/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ coreHelpers.helperMissing = function (arg) {

// Register an async handlebars helper for a given handlebars instance
function registerAsyncHelper(hbs, name, fn) {
hbs.registerAsyncHelper(name, function (options, cb) {
// Wrap the function passed in with a when.resolve so it can
// return either a promise or a value
Promise.resolve(fn.call(this, options)).then(function (result) {
hbs.registerAsyncHelper(name, function (context, options, cb) {
// Handle the case where we only get context and cb
if (!cb) {
cb = options;
options = undefined;
}

// Wrap the function passed in with a when.resolve so it can return either a promise or a value
Promise.resolve(fn.call(this, context, options)).then(function (result) {
cb(result);
}).catch(function (err) {
errors.logAndThrowError(err, 'registerAsyncThemeHelper: ' + name);
Expand Down
7 changes: 6 additions & 1 deletion core/server/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ function activateTheme(activeTheme) {
blogApp.cache = {};

// set view engine
hbsOptions = {partialsDir: [config.paths.helperTemplates]};
hbsOptions = {
partialsDir: [config.paths.helperTemplates],
onCompile: function (exhbs, source) {
return exhbs.handlebars.compile(source, {preventIndent: true});
}
};

fs.stat(themePartials, function (err, stats) {
// Check that the theme has a partials directory before trying to use it
Expand Down
5 changes: 4 additions & 1 deletion core/test/unit/server_helpers/navigation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ describe('{{navigation}} helper', function () {

before(function (done) {
utils.loadHelpers();
hbs.express3({partialsDir: [utils.config.paths.helperTemplates]});
hbs.express3({
partialsDir: [utils.config.paths.helperTemplates]
});

hbs.cachePartials(function () {
done();
});
Expand Down
1 change: 1 addition & 0 deletions core/test/unit/server_helpers/pagination_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('{{pagination}} helper', function () {
before(function (done) {
utils.loadHelpers();
hbs.express3({partialsDir: [utils.config.paths.helperTemplates]});

hbs.cachePartials(function () {
done();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"connect-slashes": "1.3.0",
"downsize": "0.0.8",
"express": "4.12.0",
"express-hbs": "0.7.11",
"express-hbs": "0.8.4",
"extract-zip": "1.0.3",
"fs-extra": "0.13.0",
"glob": "4.3.2",
Expand Down

0 comments on commit 4b05585

Please sign in to comment.