Last active
December 15, 2015 21:59
-
-
Save tracend/5330007 to your computer and use it in GitHub Desktop.
Handlebars Grunt: Using grunt-render in handlebars templates https://github.com/makesites/grunt-render/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment