mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
658a6dd284
- the proxy should always be used to access other parts of Ghost, including the urlService etc - use consistent ES6 style for requires - minimise use of lodash where possible - remove circular dependency between proxy and template util - End goal here is to enforce that the only link between helpers + the rest of Ghost is the proxy
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
// ## Template utils
|
|
const templates = {};
|
|
const _ = require('lodash');
|
|
const errors = require('@tryghost/errors');
|
|
const hbs = require('../services/themes/engine');
|
|
const i18n = require('../../server/lib/common/i18n');
|
|
|
|
// Execute a template helper
|
|
// All template helpers are register as partial view.
|
|
templates.execute = function execute(name, context, data) {
|
|
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.SafeString(partial(context, data));
|
|
};
|
|
|
|
templates.asset = _.template('<%= source %>?v=<%= version %>');
|
|
templates.link = _.template('<a href="<%= url %>"><%= text %></a>');
|
|
templates.script = _.template('<script src="<%= source %>?v=<%= version %>"></script>');
|
|
templates.input = _.template('<input class="<%= className %>" type="<%= type %>" name="<%= name %>" <%= extras %> />');
|
|
|
|
module.exports = templates;
|