mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
395079cd2f
refs #5091 - 100% coverage for new frontend/templates file - new module handles the logic for determining which template to render with
26 lines
712 B
JavaScript
26 lines
712 B
JavaScript
var templates = {},
|
|
hbs = require('express-hbs'),
|
|
errors = require('../errors');
|
|
|
|
// ## 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) {
|
|
errors.logAndThrowError('Template ' + name + ' not found.');
|
|
return;
|
|
}
|
|
|
|
// 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;
|