mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-15 10:07:07 +01:00
Rename src/eng --> src/renderers
A renderer is a thing that renders or "paints" an arbitrary format using a templating engine like Handlebars or Underscore. A generator is a thing responsible for generating a given output format like HTML or MS Word.
This commit is contained in:
57
src/renderers/underscore-generator.js
Normal file
57
src/renderers/underscore-generator.js
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
Definition of the UnderscoreGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module underscore-generator.js
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
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, '');
|
||||
|
||||
var helpers = require('./generic-helpers');
|
||||
helpers.opts = opts;
|
||||
helpers.cssInfo = cssInfo;
|
||||
|
||||
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
||||
var compiled = _.template(jst);
|
||||
var ret = compiled({
|
||||
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,
|
||||
h: helpers
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
Reference in New Issue
Block a user