Last active
August 29, 2015 13:58
-
-
Save skeate/9948073 to your computer and use it in GitHub Desktop.
Underscore template precompiling script. Compiles any .html files into templates.js. Include the file and templates can be run with templates["filename"](data).
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
var _ = require("underscore")._; | |
var fs = require("fs"); | |
fs.readdir(".", function(err,files){ | |
fs.writeFileSync('./templates.js',"templates={};"+ | |
files | |
.filter(function(f){return f.substr(-5) == ".html"}) | |
.map(function(f){return {name:'templates["'+f.substr(0,f.length-5)+'"]',source:fs.readFileSync(f).toString()};}) | |
.map(function(s){return s.name+"="+_.template(s.source).source+";";}) | |
.join('') | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment