mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-06-01 20:00:05 +01:00
ec591b9432
Try to register all javascript files found in themes as handlebars helpers. Note that, unlike all other theme files currently, format directories are ignored. I don't think there's a use case for format-specific helpers, and this gives theme developers the flexibility to put them either in top level files or organize them in subdirectories however they see fit. Note also that the theme format seems to be primarily documented in <https://github.com/fresh-standard/fresh-themes>. This newly recognized theme file type should be documented there should this branch be merged.
39 lines
961 B
CoffeeScript
39 lines
961 B
CoffeeScript
|
|
###*
|
|
Template helper definitions for Handlebars.
|
|
@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.
|
|
@method registerHelpers
|
|
###
|
|
|
|
module.exports = ( theme, opts ) ->
|
|
|
|
helpers.theme = theme
|
|
helpers.opts = opts
|
|
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
|
|
for themeHelpers in theme.jsFiles
|
|
HANDLEBARS.registerHelper require themeHelpers
|
|
return
|