2016-01-29 20:23:57 +00:00
|
|
|
###*
|
|
|
|
Definition of the UnderscoreGenerator class.
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
@module underscore-generator.js
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ = require 'underscore'
|
|
|
|
registerHelpers = require '../helpers/underscore-helpers'
|
2016-02-09 15:50:10 +00:00
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
###*
|
|
|
|
Perform template-based resume generation using Underscore.js.
|
|
|
|
@class UnderscoreGenerator
|
|
|
|
###
|
|
|
|
UnderscoreGenerator = module.exports =
|
|
|
|
|
2016-02-09 15:50:10 +00:00
|
|
|
|
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
generateSimple: ( data, tpl ) ->
|
|
|
|
try
|
|
|
|
# Compile and run the Handlebars template.
|
2016-02-09 15:50:10 +00:00
|
|
|
tpl = _.template tpl
|
|
|
|
template data
|
2016-01-29 20:23:57 +00:00
|
|
|
catch
|
2016-02-09 15:50:10 +00:00
|
|
|
HMS = require '../core/status-codes'
|
2016-01-29 20:23:57 +00:00
|
|
|
throw
|
2016-02-09 15:50:10 +00:00
|
|
|
fluenterror: HMS[if tpl then 'invokeTemplate' else 'compileTemplate']
|
2016-01-29 20:23:57 +00:00
|
|
|
inner: _error
|
|
|
|
|
2016-02-09 15:50:10 +00:00
|
|
|
|
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
generate: ( json, jst, format, cssInfo, opts, theme ) ->
|
|
|
|
|
|
|
|
# Tweak underscore's default template delimeters
|
|
|
|
delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
|
|
|
|
if opts.themeObj && opts.themeObj.delimeters
|
2016-02-09 15:50:10 +00:00
|
|
|
delims = _.mapObject delims, (val,key) -> new RegExp val, "ig"
|
2016-01-29 20:23:57 +00:00
|
|
|
_.templateSettings = delims;
|
|
|
|
|
|
|
|
# Strip {# comments #}
|
|
|
|
jst = jst.replace delims.comment, ''
|
|
|
|
|
|
|
|
ctx =
|
|
|
|
r: if format == 'html' || format == 'pdf' || format == 'png' then json.markdownify() else json
|
|
|
|
filt: opts.filters
|
|
|
|
XML: require 'xml-escape'
|
|
|
|
RAW: json
|
|
|
|
cssInfo: cssInfo
|
|
|
|
#engine: this
|
|
|
|
headFragment: opts.headFragment || ''
|
|
|
|
opts: opts
|
|
|
|
|
|
|
|
registerHelpers theme, opts, cssInfo, ctx, this
|
|
|
|
@generateSimple ctx, jst
|