1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-24 17:30:10 +00:00
This commit is contained in:
hacksalot 2016-02-09 10:50:10 -05:00
parent e191af1fb0
commit 1bc4263a46
2 changed files with 16 additions and 6 deletions

View File

@ -1,13 +1,17 @@
###* ###*
Template helper definitions for Underscore. Template helper definitions for Underscore.
@license MIT. Copyright (c) 2016 hacksalot (https://github.com/hacksalot) @license MIT. See LICENSE.md for details.
@module handlebars-helpers.js @module handlebars-helpers.js
### ###
HANDLEBARS = require('handlebars') HANDLEBARS = require('handlebars')
_ = require('underscore') _ = require('underscore')
helpers = require('./generic-helpers') helpers = require('./generic-helpers')
###* ###*
Register useful Underscore helpers. Register useful Underscore helpers.
@method registerHelpers @method registerHelpers
@ -22,3 +26,4 @@ module.exports = ( theme, opts, cssInfo, ctx, eng ) ->
if _.isFunction hVal if _.isFunction hVal
_.bind hVal, ctx _.bind hVal, ctx
, @ , @
return

View File

@ -8,7 +8,7 @@ Definition of the UnderscoreGenerator class.
_ = require 'underscore' _ = require 'underscore'
registerHelpers = require '../helpers/underscore-helpers' registerHelpers = require '../helpers/underscore-helpers'
HMSTATUS = require '../core/status-codes'
###* ###*
@ -17,22 +17,27 @@ Perform template-based resume generation using Underscore.js.
### ###
UnderscoreGenerator = module.exports = UnderscoreGenerator = module.exports =
generateSimple: ( data, tpl ) -> generateSimple: ( data, tpl ) ->
try try
# Compile and run the Handlebars template. # Compile and run the Handlebars template.
template = _.template( tpl ); tpl = _.template tpl
return template( data ); template data
catch catch
HMS = require '../core/status-codes'
throw throw
fluenterror: if template then HMSTATUS.invokeTemplate else HMSTATUS.compileTemplate, fluenterror: HMS[if tpl then 'invokeTemplate' else 'compileTemplate']
inner: _error inner: _error
generate: ( json, jst, format, cssInfo, opts, theme ) -> generate: ( json, jst, format, cssInfo, opts, theme ) ->
# Tweak underscore's default template delimeters # Tweak underscore's default template delimeters
delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template; delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
if opts.themeObj && opts.themeObj.delimeters if opts.themeObj && opts.themeObj.delimeters
delims = _.mapObject delims, (val,key) -> new RegExp( val, "ig") delims = _.mapObject delims, (val,key) -> new RegExp val, "ig"
_.templateSettings = delims; _.templateSettings = delims;
# Strip {# comments #} # Strip {# comments #}