Created
October 7, 2011 21:53
-
-
Save akdetrick/1271432 to your computer and use it in GitHub Desktop.
Node + Mustache test app
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
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