Permalink
Browse files

Adding support for handlebars compilation options

Some projects need to customize handlebars template precompilation. Now
it can be done by adding the configuration to the grunt.js file. For
example:
handlebars{

	    built: {
	        src: ['app/templates/**/*.html'],
	        dest: 'dist/debug/templates.js',
	        options:{
	        	    data: true,
	        	    stringParams: true
	        	}
	      }
}
  • Loading branch information...
1 parent 323565a commit 7b75b34c54966ce1e429262d658e10a7f20e8f4e marcus bronstein committed Oct 16, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 tasks/handlebars.js
View
@@ -30,6 +30,10 @@ module.exports = function(grunt) {
grunt.registerMultiTask("handlebars", "Compile handlebars templates and partials.", function() {
var options = grunt.helper("options", this, {namespace: "JST"});
+ var handlebarsOptions ={};
+ if(!!this.data.handlebarsOptions){
+ handlebarsOptions=this.data.handlebarsOptions;
+ };
grunt.verbose.writeflags(options, "Options");
@@ -56,7 +60,7 @@ module.exports = function(grunt) {
src = grunt.file.read(file);
try {
- compiled = require("handlebars").precompile(src);
+ compiled = require("handlebars").precompile(src,handlebarsOptions);
// if configured to, wrap template in Handlebars.template call
if(options.wrapped) {
compiled = "Handlebars.template("+compiled+")";

0 comments on commit 7b75b34

Please sign in to comment.