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

View File

@ -8,7 +8,7 @@ Definition of the UnderscoreGenerator class.
_ = require 'underscore'
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 =
generateSimple: ( data, tpl ) ->
try
# Compile and run the Handlebars template.
template = _.template( tpl );
return template( data );
tpl = _.template tpl
template data
catch
HMS = require '../core/status-codes'
throw
fluenterror: if template then HMSTATUS.invokeTemplate else HMSTATUS.compileTemplate,
fluenterror: HMS[if tpl then 'invokeTemplate' else 'compileTemplate']
inner: _error
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
delims = _.mapObject delims, (val,key) -> new RegExp( val, "ig")
delims = _.mapObject delims, (val,key) -> new RegExp val, "ig"
_.templateSettings = delims;
# Strip {# comments #}