Handlebars Plugin for DocPad
Adds support for the Handlebars templating engine to DocPad
Convention: .(inlinejs|js|anything).(handlebars|hbs|hb)
docpad install handlebars
For the plugin to support helpers and partials, you'll have to add something like the following to your docpad configuration file manually:
# ...
plugins:
handlebars:
helpers:
# Expose docpads 'getBlock' function to handlebars
getBlock: (type, additional...) ->
additional.pop() # remove the hash object
@getBlock(type).add(additional).toHTML()
partials:
title: '<h1>{{document.title}}</h1>'
goUp: '<a href="#">Scroll up</a>'
# ...
If the document extension is .(inlinejs|js).(handlebars|hbs|hb)
, the plugin will produce a precompiled template. In this case, you can customise the precompiled template via the following:
# ...
plugins:
handlebars:
precompileOpts:
wrapper: "default"
# ...
Available values for the wrapper option are:
-
"default"
: Produces a handlebars wrapper like:(function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) { ... }) })();
-
"amd"
: Produces a AMD handlebars wrapper like:define(['handlebars'], function(Handlebars) { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) { ... }); });
-
"none"
: Produces a basic wrapper like:function (Handlebars,depth0,helpers,partials,data) { ... }
Discover the change history by heading on over to the HISTORY.md
file.
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
These amazing people are maintaining this project:
- Mike Moulton mike@meltmedia.com (https://github.com/mmoulton)
- Benjamin Lupton b@lupton.cc (https://github.com/balupton)
No sponsors yet! Will you be the first?
These amazing people have contributed code to this project:
- Benjamin Lupton b@lupton.cc — view contributions
- Gilles Bouthenot — view contributions
- Mike Moulton mike@meltmedia.com — view contributions
- RobLoach — view contributions
- Tobias Birmili birmili@mecodia.de — view contributions
Unless stated otherwise all works are:
- Copyright © 2012+ Mike Moulton mike@meltmedia.com (http://meltmedia.com)
and licensed under:
- The incredibly permissive MIT License