diff --git a/src/helpers/underscore-helpers.coffee b/src/helpers/underscore-helpers.coffee index 2dbb259..22e811c 100644 --- a/src/helpers/underscore-helpers.coffee +++ b/src/helpers/underscore-helpers.coffee @@ -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 diff --git a/src/renderers/underscore-generator.coffee b/src/renderers/underscore-generator.coffee index e74ef51..38ea0c0 100644 --- a/src/renderers/underscore-generator.coffee +++ b/src/renderers/underscore-generator.coffee @@ -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 #}