2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Template helper definitions for Handlebars.
|
2016-02-14 09:10:23 +00:00
|
|
|
@license MIT. See LICENSE.md for details.
|
2016-01-27 10:29:26 +00:00
|
|
|
@module handlebars-helpers.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2018-02-01 02:11:21 +00:00
|
|
|
var HANDLEBARS, HMS, _, blockHelpers, helpers, path;
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
HANDLEBARS = require('handlebars');
|
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
helpers = require('./generic-helpers');
|
|
|
|
|
2018-02-01 02:11:21 +00:00
|
|
|
path = require('path');
|
|
|
|
|
2016-02-14 09:10:23 +00:00
|
|
|
blockHelpers = require('./block-helpers');
|
|
|
|
|
2018-02-01 02:11:21 +00:00
|
|
|
HMS = require('../core/status-codes');
|
|
|
|
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Register useful Handlebars helpers.
|
|
|
|
@method registerHelpers
|
|
|
|
*/
|
|
|
|
|
2018-02-07 10:49:02 +00:00
|
|
|
module.exports = function(theme, rez, opts) {
|
2018-02-01 12:00:59 +00:00
|
|
|
var curGlob, ex, glob, slash, wrappedHelpers;
|
2016-01-27 10:29:26 +00:00
|
|
|
helpers.theme = theme;
|
|
|
|
helpers.opts = opts;
|
2016-02-14 09:10:23 +00:00
|
|
|
helpers.type = 'handlebars';
|
|
|
|
wrappedHelpers = _.mapObject(helpers, function(hVal, hKey) {
|
|
|
|
if (_.isFunction(hVal)) {
|
2018-02-04 06:13:02 +00:00
|
|
|
return _.wrap(hVal, function(func) {
|
2016-02-14 09:10:23 +00:00
|
|
|
var args;
|
|
|
|
args = Array.prototype.slice.call(arguments);
|
|
|
|
args.shift();
|
2018-02-07 10:49:02 +00:00
|
|
|
args[args.length - 1] = rez;
|
2016-02-14 09:10:23 +00:00
|
|
|
return func.apply(this, args);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return hVal;
|
|
|
|
}, this);
|
|
|
|
HANDLEBARS.registerHelper(wrappedHelpers);
|
|
|
|
HANDLEBARS.registerHelper(blockHelpers);
|
2018-02-01 02:11:21 +00:00
|
|
|
if (_.isString(theme.helpers)) {
|
|
|
|
theme.helpers = [theme.helpers];
|
|
|
|
}
|
|
|
|
if (_.isArray(theme.helpers)) {
|
|
|
|
glob = require('glob');
|
2018-02-01 12:00:59 +00:00
|
|
|
slash = require('slash');
|
2018-02-01 02:11:21 +00:00
|
|
|
curGlob = null;
|
|
|
|
try {
|
|
|
|
_.each(theme.helpers, function(fGlob) {
|
2018-02-01 12:00:59 +00:00
|
|
|
var files;
|
2018-02-01 02:11:21 +00:00
|
|
|
curGlob = fGlob;
|
|
|
|
fGlob = path.join(theme.folder, fGlob);
|
2018-02-01 12:00:59 +00:00
|
|
|
files = glob.sync(slash(fGlob));
|
|
|
|
if (files.length > 0) {
|
|
|
|
_.each(files, function(f) {
|
|
|
|
HANDLEBARS.registerHelper(require(f));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw {
|
|
|
|
fluenterror: HMS.themeHelperLoad,
|
|
|
|
inner: er,
|
|
|
|
glob: fGlob
|
|
|
|
};
|
|
|
|
}
|
2018-02-01 02:11:21 +00:00
|
|
|
});
|
|
|
|
} catch (_error) {
|
|
|
|
ex = _error;
|
|
|
|
throw {
|
|
|
|
fluenterror: HMS.themeHelperLoad,
|
|
|
|
inner: ex,
|
|
|
|
glob: curGlob,
|
|
|
|
exit: true
|
|
|
|
};
|
|
|
|
}
|
2017-01-21 03:53:16 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=handlebars-helpers.js.map
|