mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
59b9f161dd
- the helper dir also contained some code used with helpers - utils and helper-helpers? - the goal here was for helpers to be the only thing in their folder so we can look at moving them out - all other code has been moved to services/themes for now, which is not the right place either - services/themes is a catch-all for theme storage, loading, validation, rendering and more, needs to be broken down
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// ## Template utils
|
|
const templates = {};
|
|
const _ = require('lodash');
|
|
const errors = require('@tryghost/errors');
|
|
const hbs = require('../engine');
|
|
const {i18n} = require('../../../../server/lib/common');
|
|
|
|
// 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;
|