Created
January 23, 2012 07:29
-
-
Save mattsta/1661393 to your computer and use it in GitHub Desktop.
server-side stdin/stdout mustache template compiler for hogan.js
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
#!/bin/env node | |
/***************** | |
* After getting your compiled template, you re-instantiate it client side by: | |
* var myTemplate = new Hogan.Template(compiledTemplateEvaledFunction); | |
* var renderedTemplate = myTemplate.render({field1: "someVal"}); | |
*****************/ | |
/* open le stdin */ | |
var stdin = process.openStdin(); | |
stdin.setEncoding('utf8'); | |
/* read stdin into inputBuffer */ | |
var inputBuffer = ""; | |
stdin.on("data", function(chunk) { | |
inputBuffer += chunk; | |
}); | |
/* when EOF comes in, write the compiled JS to stdout */ | |
stdin.on("end", function() { | |
var hogan = require("hogan.js"); /* make sure you `npm install hogan.js` */ | |
var compiledTemplate = hogan.compile(inputBuffer, {asString: true}); | |
process.stdout.write(compiledTemplate); | |
console.log(""); /* insert a newline just for fun */ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment