mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-07-12 13:11:08 +01:00
Refactor helpers.
Rebind Handlebars helpers to drop the pesky options hash for standalone helpers that don't need it. Move block helpers (which do need the Handlebars options/context) to a separate file for special handling.
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
|
||||
###*
|
||||
Template helper definitions for Handlebars.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module handlebars-helpers.js
|
||||
###
|
||||
|
||||
HANDLEBARS = require 'handlebars'
|
||||
_ = require 'underscore'
|
||||
helpers = require './generic-helpers'
|
||||
blockHelpers = require './block-helpers'
|
||||
|
||||
###*
|
||||
Register useful Handlebars helpers.
|
||||
@ -15,6 +16,21 @@ Register useful Handlebars helpers.
|
||||
###
|
||||
|
||||
module.exports = ( theme, opts ) ->
|
||||
|
||||
helpers.theme = theme
|
||||
helpers.opts = opts
|
||||
HANDLEBARS.registerHelper helpers
|
||||
helpers.type = 'handlebars'
|
||||
|
||||
wrappedHelpers = _.mapObject helpers, ( hVal, hKey ) ->
|
||||
if _.isFunction hVal
|
||||
_.wrap hVal, (func) ->
|
||||
args = Array.prototype.slice.call arguments
|
||||
args.shift() # lose the 1st element (func)
|
||||
args.pop() # lose the last element (the Handlebars options hash)
|
||||
func.apply @, args
|
||||
hVal
|
||||
, @
|
||||
|
||||
HANDLEBARS.registerHelper wrappedHelpers
|
||||
HANDLEBARS.registerHelper blockHelpers
|
||||
return
|
||||
|
Reference in New Issue
Block a user