Skip to content

Instantly share code, notes, and snippets.

@nmerouze
Created December 17, 2009 17:31
Show Gist options
  • Save nmerouze/258889 to your computer and use it in GitHub Desktop.
Save nmerouze/258889 to your computer and use it in GitHub Desktop.
<!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>
var sys = require('sys'), http = require('http'), posix = require('posix')
require('./underscore')
var Mustache = require('./mustache')
var actions = [];
actions.push({
path: "/",
template: "index.html",
view: {
title: "Joe",
calc: function() { return 2 + 4; }
}
})
http.createServer(function (req, res) {}).listen(8000);
http.createServer(function (req, res) {
req.addListener('complete', function() {})
}).listen(8000);
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);
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);
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);
for (var name in Mustache)
if (Object.prototype.hasOwnProperty.call(Mustache, name))
exports[name] = Mustache[name];
@quickredfox
Copy link

Why not:

  if(module && module.exports) module.exports = Mustache;

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment