1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-03 00:30:05 +01:00
HackMyResume/dist/renderers/underscore-generator.js
2016-02-01 22:52:13 -05:00

63 lines
1.7 KiB
JavaScript

/**
Definition of the UnderscoreGenerator class.
@license MIT. See LICENSE.md for details.
@module underscore-generator.js
*/
(function() {
var HMSTATUS, UnderscoreGenerator, _, registerHelpers;
_ = require('underscore');
registerHelpers = require('../helpers/underscore-helpers');
HMSTATUS = require('../core/status-codes');
/**
Perform template-based resume generation using Underscore.js.
@class UnderscoreGenerator
*/
UnderscoreGenerator = module.exports = {
generateSimple: function(data, tpl) {
var template;
try {
template = _.template(tpl);
return template(data);
} catch (_error) {
throw {
fluenterror: template ? HMSTATUS.invokeTemplate : HMSTATUS.compileTemplate,
inner: _error
};
}
},
generate: function(json, jst, format, cssInfo, opts, theme) {
var ctx, delims;
delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
if (opts.themeObj && opts.themeObj.delimeters) {
delims = _.mapObject(delims, function(val, key) {
return new RegExp(val, "ig");
});
}
_.templateSettings = delims;
jst = jst.replace(delims.comment, '');
ctx = {
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
filt: opts.filters,
XML: require('xml-escape'),
RAW: json,
cssInfo: cssInfo,
headFragment: opts.headFragment || '',
opts: opts
};
registerHelpers(theme, opts, cssInfo, ctx, this);
return this.generateSimple(ctx, jst);
}
};
}).call(this);
//# sourceMappingURL=underscore-generator.js.map