Created
June 18, 2014 09:07
-
-
Save simonmcmanus/6d2919b20b1e8cb11871 to your computer and use it in GitHub Desktop.
write object of compiled jade templates to a file - not finished
This file contains hidden or 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
'use strict'; | |
var fs = require('fs'); | |
var jade = require('jade'); | |
var path = require('path'); | |
var buildOut = function(folder, relativePath, out) { | |
var currentFolder = folder + '/' + relativePath; | |
var files = fs.readdirSync(currentFolder); | |
var counter = files.length; | |
while(counter--) { | |
var file = files[counter]; | |
var isFolder = fs.lstatSync(currentFolder + '/' + file).isDirectory(); | |
if(isFolder) { | |
buildOut(folder, relativePath + '/' + file, out); | |
}else { | |
var ext = '.jade'; | |
if(path.extname(file) === ext) { | |
var templatePath = currentFolder + '/' + file; | |
var compiled = jade.compileClient(fs.readFileSync(templatePath), { | |
client: true, | |
compileDebug: false, | |
pretty: false, | |
filename: currentFolder + '/' + file | |
}); | |
out[relativePath + '/' + file.slice(0, -5)] = compiled; | |
} | |
} | |
} | |
return out; | |
}; | |
var writeSpec = function(folder, destination) { | |
var templates = buildOut(folder, '', {}); | |
var out = []; | |
out.push('module.exports = {\n'); | |
for(var temp in templates) { | |
out.push('"' + temp + '": ' + templates[temp].toString() + ','); | |
} | |
out.push('}\n'); | |
fs.writeFile(destination, out.join(' ')); | |
}; | |
module.exports = function(folder) { | |
return buildOut(folder, '', {}); | |
}; | |
writeSpec('templates/defaults', 'out.js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment