Permalink
Browse files

Fixed djangode and template system for node v1.30

  • Loading branch information...
Anders Hellerup Madsen
Anders Hellerup Madsen committed Feb 23, 2010
1 parent aa72208 commit 8ce43c411a594fdcc39219351b1d5659e82fe995
View
@@ -1,6 +1,6 @@
var http = require('http'),
sys = require('sys'),
- posix = require('posix'),
+ fs = require('fs'),
url = require('url');
function extname(path) {
@@ -21,8 +21,13 @@ exports.serveFile = function(req, res, filename) {
return;
}
sys.puts("loading " + filename + "...");
- var promise = posix.cat(filename, encoding);
- promise.addCallback(function(data) {
+ fs.readFile(filename, encoding, function (error, data) {
+ if (error) {
+ status = 404;
+ body = '404'
+ sys.puts("Error loading " + filename);
+ return callback();
+ }
body = data;
headers = [
['Content-Type', content_type],
@@ -34,17 +39,11 @@ exports.serveFile = function(req, res, filename) {
sys.puts("static file " + filename + " loaded");
callback();
});
- promise.addErrback(function() {
- status = 404;
- body = '404'
- sys.puts("Error loading " + filename);
- callback();
- });
}
loadResponseData(function() {
res.sendHeader(status, headers);
- res.sendBody(body, encoding);
- res.finish();
+ res.write(body, encoding);
+ res.close();
});
}
@@ -58,8 +57,8 @@ function respond(res, body, content_type, status) {
res.sendHeader(status || 200, {
'Content-Type': content_type + '; charset=utf-8'
});
- res.sendBody(body, 'utf8');
- res.finish();
+ res.write(body, 'utf8');
+ res.close();
}
exports.respond = respond;
@@ -69,17 +68,17 @@ exports.redirect = redirect = function(res, location, status) {
'Content-Type': 'text/html; charset=utf-8',
'Location': location
});
- res.sendBody('Redirecting...');
- res.finish();
+ res.write('Redirecting...');
+ res.close();
}
exports.extractPost = function(req, callback) {
req.setBodyEncoding('utf-8');
var body = '';
- req.addListener('body', function(chunk) {
+ req.addListener('data', function(chunk) {
body += chunk;
});
- req.addListener('complete', function() {
+ req.addListener('end', function() {
callback(http.parseUri('http://fake/?' + body).params);
});
}
View
@@ -2,7 +2,7 @@
/*global require, process, exports, escape */
var sys = require('sys');
-var posix = require('posix');
+var fs = require('fs');
var cache = {};
var template_path = '/tmp';
@@ -16,12 +16,13 @@ function load(name, parse_function, callback) {
}
} else {
if (callback) {
- posix.cat(template_path + '/' + name).addCallback(function(s) {
+ fs.readfile(template_path + '/' + name, function (error, s) {
+ if (error) { callback(error); }
cache[name] = parse_function(s);
- callback(cache[name]);
+ callback(false, cache[name]);
});
} else {
- var content = posix.cat(template_path + '/' + name).wait();
+ var content = fs.readFileSync(template_path + '/' + name);
cache[name] = parse_function(content);
return cache[name];
}
View
@@ -238,7 +238,7 @@ function make_nodelist() {
process.mixin(Parser.prototype, {
- callbacks: template_defaults.callbacks,
+ tags: template_defaults.tags,
parse: function () {
@@ -259,7 +259,7 @@ process.mixin(Parser.prototype, {
//sys.debug('' + this.indent + ': ' + token);
- callback = this.callbacks[token.type];
+ callback = this.tags[token.type];
if (callback && typeof callback === 'function') {
node_list.append( callback(this, token), token.type );
} else {
Oops, something went wrong.

0 comments on commit 8ce43c4

Please sign in to comment.