1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 18:06:23 +00:00
HackMyResume/src/renderers/underscore-generator.coffee

58 lines
1.4 KiB
CoffeeScript
Raw Normal View History

###*
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
###*
Perform template-based resume generation using Underscore.js.
@class UnderscoreGenerator
###
UnderscoreGenerator = module.exports =
2016-02-09 15:50:10 +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
catch
2016-02-09 15:50:10 +00:00
HMS = require '../core/status-codes'
throw
2016-02-09 15:50:10 +00:00
fluenterror: HMS[if tpl then 'invokeTemplate' else 'compileTemplate']
inner: _error
2016-02-09 15:50:10 +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"
_.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