A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.
Usage
In templates/test.html
:
Hello {{place}}
In your gulpfile:
var compiler = ; gulp;
In your code:
var templates = ; var html = templatestest console; // <p>Hello world</p>
This will compile the templates into a JavaScript AMD module using hogan.compile
.
It will require('hogan')
so that module needs to be available. You can change the name/path of the hogan module at compile time with options.hoganModule
.
Alternatively you can pass an object to have it populated with executable templates, which is useful if you need templates as part of a build step, for example:
var compiler = ;var templates = {}; gulp; gulp;
Parameters
- dest
string|object
- Either the name of a file or an object - if using an object it will be populated with compiled template code and no file will be outputted (so all string output related options below are ignored)
- options
object
- Options passed to the hogan task
Options
string
newLine The line delimiter, defaults to your operating system's newline. Ignored if dest
is an object.
string
wrapper Either amd
, commonjs
or false
for no wrapper, defaults to amd
. If wrapper is false
a local var templates
will be defined containing the templates. Ignored if dest
is an object.
object
templateOptions Options passed through to hogan.compile
. The asString
option will be set depending on whether output is a file or an object, any passed setting is ignored.
function(file)
templateName A function that will be passed the file and should return a name for the template. By default uses the relative path and basename of the file without an extension.
'templates'
templatesVariableName Override the variable name used for the templates, default is templates
. Useful when not using a wrapper in the browser and don't want it assigned to window.templates
.
string
hoganModule The name of the hogan module in your app, defaults to hogan
. If you're not using a wrapper then the global Hogan
must be available.