2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Definition of the UnderscoreGenerator class.
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
@module underscore-generator.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2016-02-09 20:27:34 +00:00
|
|
|
var UnderscoreGenerator, _, registerHelpers;
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
registerHelpers = require('../helpers/underscore-helpers');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform template-based resume generation using Underscore.js.
|
|
|
|
@class UnderscoreGenerator
|
|
|
|
*/
|
|
|
|
|
|
|
|
UnderscoreGenerator = module.exports = {
|
|
|
|
generateSimple: function(data, tpl) {
|
2016-02-09 20:27:34 +00:00
|
|
|
var HMS, t;
|
2016-01-27 10:29:26 +00:00
|
|
|
try {
|
2016-02-09 20:27:34 +00:00
|
|
|
t = _.template(tpl);
|
|
|
|
return t(data);
|
2016-01-27 10:29:26 +00:00
|
|
|
} catch (_error) {
|
2016-02-09 20:27:34 +00:00
|
|
|
HMS = require('../core/status-codes');
|
2016-01-27 10:29:26 +00:00
|
|
|
throw {
|
2016-02-09 20:27:34 +00:00
|
|
|
fluenterror: HMS[t ? 'invokeTemplate' : 'compileTemplate'],
|
2016-01-27 10:29:26 +00:00
|
|
|
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);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=underscore-generator.js.map
|