diff --git a/src/handlebars.plugin.coffee b/src/handlebars.plugin.coffee index 85a8026..2841eaf 100644 --- a/src/handlebars.plugin.coffee +++ b/src/handlebars.plugin.coffee @@ -15,19 +15,26 @@ module.exports = (BasePlugin) -> super docpad = @docpad config = @config - handlebars = @handlebars = require('handlebars') + @handlebars = require('handlebars') @precompileOpts = @config.precompileOpts || {} + # Generate Before + generateBefore: -> + # Add the template helper as a Handlebars helper + for own key,value of @docpad.getTemplateData() + if Object::toString.call(value) is '[object Function]' + @handlebars.registerHelper(key, value) + # Add helpers, if defined in docpad.cson if @config.helpers for own name,helper of @config.helpers - handlebars.registerHelper(name, helper) + @handlebars.registerHelper(name, helper) # Add partials, if defined in docpad.cson if @config.partials for own name,partial of @config.partials - handlebars.registerPartial(name, partial) + @handlebars.registerPartial(name, partial) # Render some content render: (opts) -> @@ -48,7 +55,7 @@ module.exports = (BasePlugin) -> argv.amdPath ?= "" pre = post = ""; - + # slug for {src}/tpl/a/abc/test.js.handlebars is "tpl-a-abc-test" templateName = opts.file.attributes.slug; if (argv.wrapper is "amd") diff --git a/test/docpad.cson b/test/docpad.cson index 75c00e7..579ccc3 100644 --- a/test/docpad.cson +++ b/test/docpad.cson @@ -7,4 +7,7 @@ partials: partial1: '

{{document.example}}

' partial2: 'Scroll up' -} \ No newline at end of file + + # Increase the render passes so that the include helper works. + renderPasses: 2 +} diff --git a/test/out-expected/standard-template-helpers.html b/test/out-expected/standard-template-helpers.html new file mode 100644 index 0000000..7b73ba7 --- /dev/null +++ b/test/out-expected/standard-template-helpers.html @@ -0,0 +1,29 @@ +

Standard Template Helpers

+ +

include "handlebars-helper.html.hbs"

+ +

Testing Helpers

+ + +

getEnvironment

+ +development + + +

getEnvironments

+ + + development + + + +

getBlock blockname

+ +[object Object] +[object Object] +[object Object] + + +

getPath "handlebars-helper.html" "test"

+ +test/handlebars-helper.html diff --git a/test/src/documents/standard-template-helpers.html.hbs b/test/src/documents/standard-template-helpers.html.hbs new file mode 100644 index 0000000..af29eac --- /dev/null +++ b/test/src/documents/standard-template-helpers.html.hbs @@ -0,0 +1,29 @@ +

Standard Template Helpers

+ +

include "handlebars-helper.html.hbs"

+ +{{{include "handlebars-helper.html.hbs"}}} + + +

getEnvironment

+ +{{getEnvironment}} + + +

getEnvironments

+ +{{#each getEnvironments}} + {{this}} +{{/each}} + + +

getBlock blockname

+ +{{{getBlock "scripts"}}} +{{{getBlock "styles"}}} +{{{getBlock "meta"}}} + + +

getPath "handlebars-helper.html" "test"

+ +{{getPath "handlebars-helper.html" "test"}}