Created
December 17, 2009 17:31
-
-
Save nmerouze/258889 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
| <title>My Framework</title> | |
| </head> | |
| <body> | |
| {{title}} spends {{calc}} | |
| </body> | |
| </html> |
This file contains hidden or 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 sys = require('sys'), http = require('http'), posix = require('posix') | |
| require('./underscore') | |
| var Mustache = require('./mustache') |
This file contains hidden or 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 actions = []; | |
| actions.push({ | |
| path: "/", | |
| template: "index.html", | |
| view: { | |
| title: "Joe", | |
| calc: function() { return 2 + 4; } | |
| } | |
| }) |
This file contains hidden or 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
| http.createServer(function (req, res) {}).listen(8000); |
This file contains hidden or 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
| http.createServer(function (req, res) { | |
| req.addListener('complete', function() {}) | |
| }).listen(8000); |
This file contains hidden or 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
| http.createServer(function (req, res) { | |
| req.addListener('complete', function() { | |
| var action = _(actions).chain().select(function(a) { return req.uri.path == a.path }).first().value() | |
| }) | |
| }).listen(8000); |
This file contains hidden or 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
| http.createServer(function (req, res) { | |
| req.addListener('complete', function() { | |
| var action = _(actions).chain().select(function(a) { return req.uri.path == a.path }).first().value() | |
| if (_.isEmpty(action)) { | |
| res.sendHeader(404, {'Content-Type': 'text/plain'}) | |
| res.sendBody("Error") | |
| res.finish() | |
| } else {} | |
| }) | |
| }).listen(8000); |
This file contains hidden or 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
| http.createServer(function (req, res) { | |
| req.addListener('complete', function() { | |
| var action = _(actions).chain().select(function(a) { return req.uri.path == a.path }).first().value() | |
| if (_.isEmpty(action)) { | |
| res.sendHeader(404, {'Content-Type': 'text/plain'}) | |
| res.sendBody("Error") | |
| res.finish() | |
| } else { | |
| posix.cat("./templates/" + action.template).addCallback(function(template) { | |
| res.sendHeader(200, {'Content-Type': 'text/html'}) | |
| res.sendBody(Mustache.to_html(template, action.view)) | |
| res.finish() | |
| }) | |
| } | |
| }) | |
| }).listen(8000); |
This file contains hidden or 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
| for (var name in Mustache) | |
| if (Object.prototype.hasOwnProperty.call(Mustache, name)) | |
| exports[name] = Mustache[name]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not:
?