2015-12-06 21:19:55 +00:00
|
|
|
/**
|
|
|
|
Underscore template generate for FluentCV.
|
|
|
|
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(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
|
2015-12-10 15:28:19 +00:00
|
|
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|