51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
// var dust = require("dustjs-linkedin");
|
|
var dust = require("dustjs-helpers");
|
|
var fs = require("fs");
|
|
const path = require("path");
|
|
|
|
dust.helpers.dumpParameters = function(chunk, context, bodies, params) {
|
|
// Dump the parameters to a dust helper to figure out what is passed
|
|
// to a helper. I figure I need to make sure I'm passing
|
|
// approximately the same information to my render functions if I
|
|
// end up supporting custom helpers in the future to make sure
|
|
// helpers can be ported easily.
|
|
// console.log(JSON.stringify(Array.prototype.slice.call(arguments)));
|
|
console.log("chunk: ", chunk);
|
|
console.log("context: ", JSON.stringify(context));
|
|
console.log("bodies: ", bodies);
|
|
console.log("params: ", params);
|
|
}
|
|
|
|
var argv = process.argv.slice(2);
|
|
if (argv.length < 1) {
|
|
console.error("Expecting only 1 argument (a path to a template)");
|
|
process.exit(1);
|
|
}
|
|
var context = JSON.parse(fs.readFileSync(0, "utf-8"));
|
|
var main_template = path.parse(argv[0])["name"];
|
|
|
|
for (var i = 0, len = argv.length; i < len; ++i) {
|
|
var filename = path.parse(argv[i])["name"];
|
|
|
|
try {
|
|
var template_source = fs.readFileSync(argv[i], "utf-8");
|
|
} catch (err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
|
|
var compiled_template = dust.compile(template_source, filename);
|
|
dust.loadSource(compiled_template);
|
|
|
|
}
|
|
|
|
dust.render(main_template, context, function(err, out) {
|
|
if(err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
} else {
|
|
console.log(out);
|
|
process.exit(0);
|
|
}
|
|
});
|