a grunt task to compile/precompile hogan templates
Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-hogan --save-dev
Then add this line to your project's grunt.js gruntfile:
grunt.loadNpmTasks('grunt-hogan');To compile multiple mustache templates to a single output file, your config should look like this:
grunt.initConfig({
//...
hogan: {
//desired target name
mytarget : {
//Wildcard of desired templates
templates : "view/**/*.hogan",
//output destination
output : "hulkingup.js"
}
},
//...
});By default, the all compiled templates in a target will be "bound" together by the default "binder" (which
is itself a pre-compiled template). The "default" binder generates javascript
that is designed to work both as a node.js module and in the browser via a
<script/> tag. Also supported are the "hulk" binder (should output similarly to
hogan's "hulk" command line tool...which is "vanilla" javascript), and the "nodejs"
binder, which provides a pure node.js format. You can also create your own binder templates to support other usages.
To specify a binder, use a "binderName" directive:
//...
mytarget : {
templates : "view/**/*.hogan",
output : "hulkingup.js",
binderName : "hulk"
}
//...To specify a custom binder, supply a path for the "binder" attribute that resolves to a binder module:
//...
binder : __dirname + "/my/custom/binder.js"
//...See the *custombinder* targets in the
example gruntfile
for futher
detail on creating and using custom binders.
There can be multiple template patterns:
//...
mytarget : {
//...
templates : ["view/wwf/*.hogan", "view/wcw/*.hogan"],
//...
}
//...In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
- 0.2.0 - in progress
- 0.1.1 - Breaking Changes and Custom Binder Support
- "render" directive has been discarded
- "options" notation has been discarded (supply attributes directly as keys on the target)
##Acknowledgements
- a comment by "baz" here pointed me in the right direction
Copyright (c) 2013 Elliott B. Edwards
Licensed under the MIT license.