Grunt task to compile Dust.js templates.
Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-dustjs
.
Then add this line to your project's grunt.js
gruntfile:
grunt.loadNpmTasks('grunt-dustjs');
Inside your grunt.js
file, add a section named dustjs
. This section specifies the Dust.js template files to compile.
This defines what files this task will process and should contain key:value pairs.
The key (destination) should be an unique filepath (supports grunt.template) and the value (source) should be a filepath or an array of filepaths (supports minimatch).
Also, you can use fullname
option to customize template variable name.
// project configuration
grunt.initConfig({
dustjs: {
compile: {
files: {
"js/templates.js": ["src/templates/**/*.html"]
}
}
},
});
// project configuration
grunt.initConfig({
dustjs: {
compile: {
files: {
"js/templates.js": ["src/templates/**/*.html"]
},
options: {
fullname: function(filepath) {
return path.relative('templates/all', path.dirname(filepath)).split(path.sep) // folder names
.concat([path.basename(filepath, path.extname(filepath))]) // template name
.join('.');
}
}
}
},
});
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.
- 08/12/2012 - 0.2: Add namespace support.
- 25/09/2012 - 0.1.2: Initial release.
Copyright (c) 2012 Stanislav Lesnikov Licensed under the MIT license.