public
Last active

Handlebars Grunt: Using grunt-render in handlebars templates https://github.com/makesites/grunt-render/

  • Download Gist
handlebars.grunt.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
hbs.registerHelper('grunt', function(type, name) {
var options = {};
// fallbacks...
// if there is no type, exit now
if(typeof type == "undefined") return;
options.type = type;
// fallback for name
if(typeof name == "string"){
options.name = name;
}
// fn will compile the body section between the tags
var files = arguments[arguments.length-1].fn || false;
if( files ){
options.files = files();
};
// remove last (internal) argument
//var options = arguments;
//delete options[arguments.length-1];
var grunt = require('grunt-render')( options );
var html = grunt[type]( options );
return new hbs.SafeString( html );
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.