2017-04-04 19:07:35 +03:00
|
|
|
var templates = {},
|
|
|
|
_ = require('lodash'),
|
2017-12-12 00:47:46 +03:00
|
|
|
proxy = require('./proxy'),
|
2017-12-14 05:01:23 +03:00
|
|
|
hbs = require('../services/themes/engine');
|
2013-11-28 06:45:01 +04:00
|
|
|
|
|
|
|
// ## Template utils
|
|
|
|
|
2013-12-02 03:31:55 +04:00
|
|
|
// Execute a template helper
|
|
|
|
// All template helpers are register as partial view.
|
2019-03-09 22:35:19 +03:00
|
|
|
templates.execute = function execute(name, context, data) {
|
2013-12-02 03:31:55 +04:00
|
|
|
var partial = hbs.handlebars.partials[name];
|
2013-11-28 06:45:01 +04:00
|
|
|
|
2013-12-02 03:31:55 +04:00
|
|
|
if (partial === undefined) {
|
2017-12-12 00:47:46 +03:00
|
|
|
throw new proxy.errors.IncorrectUsageError({
|
|
|
|
message: proxy.i18n.t('warnings.helpers.template.templateNotFound', {name: name})
|
2016-10-06 15:27:35 +03:00
|
|
|
});
|
2013-12-02 03:31:55 +04:00
|
|
|
}
|
2013-11-28 06:45:01 +04:00
|
|
|
|
2013-12-02 03:31:55 +04:00
|
|
|
// If the partial view is not compiled, it compiles and saves in handlebars
|
|
|
|
if (typeof partial === 'string') {
|
2014-01-23 20:22:25 +04:00
|
|
|
hbs.registerPartial(partial);
|
2013-12-02 03:31:55 +04:00
|
|
|
}
|
2013-11-28 06:45:01 +04:00
|
|
|
|
2019-03-09 22:35:19 +03:00
|
|
|
return new hbs.SafeString(partial(context, data));
|
2013-11-28 06:45:01 +04:00
|
|
|
};
|
|
|
|
|
2017-04-04 19:07:35 +03:00
|
|
|
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 %> />');
|
|
|
|
|
2014-09-10 08:06:24 +04:00
|
|
|
module.exports = templates;
|