1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-10-05 23:15:12 +01:00
HackMyResume/src/eng/underscore-generator.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-12-06 21:19:55 +00:00
/**
2015-12-17 15:15:59 +00:00
Definition of the UnderscoreGenerator class.
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
2015-12-06 21:19:55 +00:00
*/
(function() {
var _ = require('underscore');
2015-12-17 01:13:27 +00:00
module.exports = function( json, jst, format, cssInfo, opts, theme ) {
2015-12-06 21:19:55 +00:00
// Tweak underscore's default template delimeters
var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
if( opts.themeObj && opts.themeObj.delimeters ) {
2015-12-07 21:39:59 +00:00
delims = _.mapObject( delims, function(val,key) {
2015-12-10 02:44:35 +00:00
return new RegExp( val, "ig");
2015-12-07 21:39:59 +00:00
});
}
_.templateSettings = delims;
2015-12-06 21:19:55 +00:00
// Strip {# comments #}
2015-12-07 21:39:59 +00:00
jst = jst.replace( delims.comment, '');
2015-12-06 21:19:55 +00:00
// Compile and run the template. TODO: avoid unnecessary recompiles.
2015-12-07 21:39:59 +00:00
var compiled = _.template(jst);
var ret = compiled({
2015-12-09 09:32:39 +00:00
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
2015-12-07 21:39:59 +00:00
filt: opts.filters,
2015-12-09 05:13:58 +00:00
XML: require('xml-escape'),
RAW: json,
2015-12-07 21:39:59 +00:00
cssInfo: cssInfo,
headFragment: opts.headFragment || ''
});
return ret;
2015-12-06 21:19:55 +00:00
};
}());