Ghost/core/server/helpers/template.js
Katharina Irrgang d81bc91bd2 Error creation (#7477)
refs #7116, refs #2001

- Changes the way Ghost errors are implemented to benefit from proper inheritance
- Moves all error definitions into a single file
- Changes the error constructor to take an options object, rather than needing the arguments to be passed in the correct order.
- Provides a wrapper so that any errors that haven't already been converted to GhostErrors get converted before they are displayed.

Summary of changes:

* 🐛  set NODE_ENV in config handler
*   add GhostError implementation (core/server/errors.js)
  - register all errors in one file
  - inheritance from GhostError
  - option pattern
* 🔥  remove all error files
*   wrap all errors into GhostError in case of HTTP
* 🎨  adaptions
  - option pattern for errors
  - use GhostError when needed
* 🎨  revert debug deletion and add TODO for error id's
2016-10-06 13:27:35 +01:00

28 lines
814 B
JavaScript

var templates = {},
hbs = require('express-hbs'),
errors = require('../errors'),
i18n = require('../i18n');
// ## Template utils
// Execute a template helper
// All template helpers are register as partial view.
templates.execute = function (name, context, options) {
var partial = hbs.handlebars.partials[name];
if (partial === undefined) {
throw new errors.IncorrectUsageError({
message: i18n.t('warnings.helpers.template.templateNotFound', {name: name})
});
}
// If the partial view is not compiled, it compiles and saves in handlebars
if (typeof partial === 'string') {
hbs.registerPartial(partial);
}
return new hbs.handlebars.SafeString(partial(context, options));
};
module.exports = templates;