1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/dist/helpers/handlebars-helpers.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
/**
Template helper definitions for Handlebars.
@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');
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
*/
module.exports = function(theme, opts) {
var curGlob, ex, glob, slash, wrappedHelpers;
2016-01-27 10:29:26 +00:00
helpers.theme = theme;
helpers.opts = opts;
helpers.type = 'handlebars';
wrappedHelpers = _.mapObject(helpers, function(hVal, hKey) {
if (_.isFunction(hVal)) {
_.wrap(hVal, function(func) {
var args;
args = Array.prototype.slice.call(arguments);
args.shift();
args.pop();
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');
slash = require('slash');
2018-02-01 02:11:21 +00:00
curGlob = null;
try {
_.each(theme.helpers, function(fGlob) {
var files;
2018-02-01 02:11:21 +00:00
curGlob = fGlob;
fGlob = path.join(theme.folder, fGlob);
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
};
}
}
2016-01-27 10:29:26 +00:00
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=handlebars-helpers.js.map