Skip to content

Instantly share code, notes, and snippets.

@akdetrick
Created October 7, 2011 21:53
Show Gist options
  • Save akdetrick/1271432 to your computer and use it in GitHub Desktop.
Save akdetrick/1271432 to your computer and use it in GitHub Desktop.
Node + Mustache test app
var http = require('http');
var stache = require('mustache');
var Templates = {
index: "\
<h1>Mustache Test</h1>\
<p>Hello {{name}}</p>\
"
};
var TemplateBuilder = {
_pre: "<html><head></head><body>",
_post: "</body></html>",
build: function( template ) {
if ( !template ) {
console.warn('bad argument passed into TemplateBuilder.build');
return;
};
return this._pre + Templates[template] + this._post;
}
};
http.createServer(function (req, res) {
var view = { //view - use actions for views
name: 'test'
};
var html = stache.to_html(TemplateBuilder.build('index'), view);
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment