-
-
Save davidtheclark/4282378 to your computer and use it in GitHub Desktop.
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
fs = require 'fs' | |
pathutil = require 'path' | |
jade = require 'jade' | |
parseFiles = (dirname) -> | |
filenames = fs.readdirSync dirname | |
for file in filenames | |
continue if file.slice(0,1) is '.' | |
path = pathutil.join dirname, file | |
stats = fs.statSync pathutil.join dirname, path | |
if stats.isDirectory() | |
parseFiles(file) | |
else if file.slice(file.length - 5) is '.jade' | |
fileContents = fs.readFileSync path, 'utf8' | |
compiled = jade.compile fileContents, | |
client: true | |
compileDebug: false | |
filename: file | |
writeToOutput compiled, file.replace '.jade', '' | |
writeToOutput = (fn, fnName) -> | |
finalFnName = "Templates.#{fnName}" | |
fnString = fn.toString().replace('function anonymous(', "function #{finalFnName}(") | |
outFileStream.write(fnString) | |
jadeFilePath = process.argv[2] || '.' | |
outFilePath = process.argv[3] || './templates.js' | |
outFileStream = fs.createWriteStream outFilePath, | |
flags: 'w' | |
outFileStream.write("var Templates = {};\n") | |
parseFiles jadeFilePath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment