Simple node template compiler

This commit is contained in:
kpdecker
2011-07-30 12:25:41 -05:00
parent aeda7e389f
commit 6a6edf5ae6
2 changed files with 30 additions and 1 deletions
Executable
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env node
var fs = require('fs'),
handlebars = require('../lib/handlebars');
var argv = require('optimist').argv;
var template = argv._[0];
// Show help prompt if requested or if the
// incorrect usage options are supplied
if (argv.h || argv.help || !template) {
console.error("Usage: handlebars.js template");
return;
}
// First figure out what our output looks like
fs.readFile(template, 'utf8', function(err, data) {
if (err) {
throw err;
}
var options = {};
var ast = handlebars.parse(data);
var environment = new handlebars.Compiler().compile(ast, options);
console.log(new handlebars.JavaScriptCompiler().compile(environment, options));
});
+3 -1
View File
@@ -12,5 +12,7 @@
"optimist": "~0.2"
},
"devDependencies": {},
"main": "bin/billy"
"bin": {
"handlebars": "bin/handlebars"
}
}