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

53 lines
1.2 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.
@module underscore-generator.js
2015-12-06 21:19:55 +00:00
*/
(function() {
2015-12-06 21:19:55 +00:00
var _ = require('underscore');
/**
Perform template-based resume generation using Underscore.js.
@class UnderscoreGenerator
*/
var UnderscoreGenerator = module.exports = {
generate: function( json, jst, format, cssInfo, opts, theme ) {
// Tweak underscore's default template delimeters
var 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;
// Strip {# comments #}
jst = jst.replace( delims.comment, '');
// Compile and run the template. TODO: avoid unnecessary recompiles.
var compiled = _.template(jst);
var ret = compiled({
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
filt: opts.filters,
XML: require('xml-escape'),
RAW: json,
cssInfo: cssInfo,
headFragment: opts.headFragment || ''
2015-12-07 21:39:59 +00:00
});
return ret;
2015-12-07 21:39:59 +00:00
}
2015-12-06 21:19:55 +00:00
};
2015-12-06 21:19:55 +00:00
}());