1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-25 01:40:10 +00:00
HackMyResume/dist/renderers/underscore-generator.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

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-14 01:40:17 +00:00
var UnderscoreGenerator, _, escapeLaTeX, registerHelpers;
2016-01-27 10:29:26 +00:00
_ = require('underscore');
registerHelpers = require('../helpers/underscore-helpers');
2016-02-14 01:40:17 +00:00
require('../utils/string');
escapeLaTeX = require('escape-latex');
2016-01-27 10:29:26 +00:00
/**
Perform template-based resume generation using Underscore.js.
@class UnderscoreGenerator
*/
UnderscoreGenerator = module.exports = {
generateSimple: function(data, tpl) {
var HMS, t;
2016-01-27 10:29:26 +00:00
try {
t = _.template(tpl);
return t(data);
2016-01-27 10:29:26 +00:00
} catch (_error) {
HMS = require('../core/status-codes');
2016-01-27 10:29:26 +00:00
throw {
fluenterror: HMS[t ? 'invokeTemplate' : 'compileTemplate'],
2016-01-27 10:29:26 +00:00
inner: _error
};
}
},
generate: function(json, jst, format, cssInfo, opts, theme) {
2016-02-14 01:40:17 +00:00
var ctx, delims, r, traverse;
2016-01-27 10:29:26 +00:00
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;
2016-02-14 01:40:17 +00:00
r = null;
switch (format) {
case 'html':
r = json.markdownify();
break;
case 'pdf':
r = json.markdownify();
break;
case 'png':
r = json.markdownify();
break;
case 'latex':
traverse = require('traverse');
r = traverse(json).map(function(x) {
if (this.isLeaf && String.is(this.node)) {
return escapeLaTeX(this.node);
}
return this.node;
});
break;
default:
r = json;
}
2016-01-27 10:29:26 +00:00
ctx = {
2016-02-14 01:40:17 +00:00
r: r,
2016-01-27 10:29:26 +00:00
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