Created
June 23, 2014 02:43
-
-
Save terribleplan/c9033e963b0019cf81f7 to your computer and use it in GitHub Desktop.
Grunt render-handlebars
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
//I'll probably turn this into an actual plugin at some point, but for now this is a simple way to compile handlebars templates statically | |
grunt.registerMultiTask('render-handlebars', function () { | |
var done = this.async(); | |
var inputFile = this.data["inputFile"], | |
outputFile = this.data["outputFile"], | |
removeInput = !!(this.data["removeTemplate"] || false), | |
templateName = this.data["templateName"] || "index"; | |
try { | |
var Handlebars = require('handlebars'); | |
Handlebars.partials = require(inputFile); | |
grunt.file.write(outputFile, Handlebars.partials[templateName]({})); | |
grunt.log.writeln("File " + outputFile + " written from ['" + templateName + "'] of " + inputFile); | |
if (!removeInput) { | |
done(true); | |
return; | |
} | |
grunt.file.delete(inputFile); | |
grunt.log.writeln(inputFile + " deleted."); | |
done(true); | |
} catch (e) { | |
grunt.log.error(e.message); | |
done(false); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment