Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Remove process.mixin (which is deprecated/removed from Node) #7

Open
wants to merge 3 commits into
from
View
@@ -1,5 +1,5 @@
var http = require('http'),
- sys = require('sys'),
+ util = require('util'),
fs = require('fs'),
url = require('url'),
querystring = require('querystring')
@@ -22,13 +22,14 @@ exports.serveFile = function(req, res, filename) {
callback();
return;
}
- sys.puts("loading " + filename + "...");
+ util.puts("loading " + filename + "...");
fs.readFile(filename, encoding, function (error, data) {
if (error) {
status = 404;
- body = '404'
- sys.puts("Error loading " + filename);
- return callback();
+ body = '404';
+ util.puts("Error loading " + filename);
+ callback();
+ return;
}
body = data;
headers = [
@@ -38,7 +39,7 @@ exports.serveFile = function(req, res, filename) {
: body.length
]
];
- sys.puts("static file " + filename + " loaded");
+ util.puts("static file " + filename + " loaded");
callback();
});
}
@@ -47,12 +48,12 @@ exports.serveFile = function(req, res, filename) {
res.write(body, encoding);
res.close();
});
-}
+};
exports.serve = function(app, port) {
- sys.puts('Server on http://127.0.0.1:' + port + '/');
+ util.puts('Server on http://127.0.0.1:' + port + '/');
return http.createServer(app).listen(port);
-}
+};
function respond(res, body, content_type, status) {
content_type = content_type || 'text/html';
@@ -83,9 +84,9 @@ exports.extractPost = function(req, callback) {
req.addListener('end', function() {
callback(querystring.parse(url.parse('http://fake/?' + body).query));
});
-}
+};
-var debuginfo = {}
+var debuginfo = {};
exports.debuginfo = debuginfo;
exports.makeApp = function(urls, options) {
@@ -104,10 +105,10 @@ exports.makeApp = function(urls, options) {
var view = show_404;
var args = [req, res];
for (var pair, i = 0; pair = compiled[i]; i++) {
- //sys.puts("Matching " + pair[0] + " against path " + path);
+ //util.puts("Matching " + pair[0] + " against path " + path);
var match = pair[0](path);
if (match) {
- //sys.puts(" matched! " + match);
+ //util.puts(" matched! " + match);
// Add matched bits to args
match.slice(1).forEach(function(arg) {
args.push(arg);
@@ -122,7 +123,7 @@ exports.makeApp = function(urls, options) {
debuginfo.last_e = e;
show_500(req, res, e);
}
- }
+ };
app.urls = {};
urls.forEach(function (item) { app.urls[item[2]] = item[0]; });
return app;
@@ -133,10 +134,10 @@ function default_show_404(req, res) {
'<h1>404</h1>', 'text/html', 404
);
}
-exports.default_show_404 = default_show_404
+exports.default_show_404 = default_show_404;
function default_show_500(req, res, e) {
- var msg = ''
+ var msg = '';
if ('stack' in e && 'type' in e) {
msg = (
'<p><strong>' + e.type + '</strong></p><pre>' +
@@ -147,7 +148,7 @@ function default_show_500(req, res, e) {
}
respond(res, '<h1>500</h1>' + msg, 'text/html', 500);
}
-exports.default_show_500 = default_show_500
+exports.default_show_500 = default_show_500;
exports.mime = mime = {
lookup : function(ext, fallback) {
View
@@ -1,7 +1,6 @@
/*jslint eqeqeq: true, undef: true, regexp: false */
/*global require, process, exports, escape */
-var sys = require('sys');
var fs = require('fs');
var template_system = require('./template');
View
@@ -1,10 +1,11 @@
/*jslint laxbreak: true, eqeqeq: true, undef: true, regexp: false */
/*global require, process, exports */
-var sys = require('sys');
+var util = require('util');
var string_utils = require('../utils/string');
var html = require('../utils/html');
var iter = require('../utils/iter');
+var mixin = require('../utils/mixin').mixin;
function normalize(value) {
if (typeof value !== 'string') { return value; }
@@ -26,7 +27,7 @@ function Token(type, contents) {
this.contents = contents;
}
-process.mixin(Token.prototype, {
+mixin(Token.prototype, {
split_contents: function () {
return string_utils.smart_split(this.contents);
}
@@ -59,7 +60,7 @@ function tokenize(input) {
var res = consume_until("{{", "{%");
if (res[0]) { token_list.push( new Token('text', res[0]) ); }
-
+
if (res[1] === "{{") { return variable_tag; }
if (res[1] === "{%") { return template_tag; }
return undefined;
@@ -105,7 +106,7 @@ var FilterExpression = function (expression, constant) {
var parsed = this.consume(expression);
- //sys.debug(expression + ' => ' + sys.inspect( parsed ) );
+ //util.debug(expression + ' => ' + util.inspect( parsed ) );
if (!parsed) {
throw this.error(expression);
@@ -128,20 +129,20 @@ var FilterExpression = function (expression, constant) {
if (parsed.constant !== undefined) { this.constant = normalize(parsed.constant); }
if (parsed.variable !== undefined) { this.variable = normalize(parsed.variable); }
- if (parsed.filter_name) {
+ if (parsed.filter_name) {
this.filter_list.push( this.make_filter_token(parsed) );
}
parsed = this.consume(expression);
- //sys.debug(expression + ' => ' + sys.inspect( parsed ) );
+ //util.debug(expression + ' => ' + util.inspect( parsed ) );
}
- //sys.debug(expression + ' => ' + sys.inspect( this ) );
+ //util.debug(expression + ' => ' + util.inspect( this ) );
};
-process.mixin(FilterExpression.prototype, {
+mixin(FilterExpression.prototype, {
consume: function (expression) {
var m = filter_re.exec(expression);
@@ -189,7 +190,7 @@ process.mixin(FilterExpression.prototype, {
return filter(p, arg, safety);
} else {
// throw 'Cannot find filter';
- sys.debug('Cannot find filter ' + c.name);
+ util.debug('Cannot find filter ' + c.name);
return p;
}
}, value);
@@ -239,26 +240,26 @@ function make_nodelist() {
return node_list;
}
-process.mixin(Parser.prototype, {
+mixin(Parser.prototype, {
parse: function () {
-
+
var stoppers = Array.prototype.slice.apply(arguments);
var node_list = make_nodelist();
var token = this.token_list[0];
var tag = null;
- //sys.debug('' + this.indent++ + ':starting parsing with stoppers ' + stoppers.join(', '));
+ //util.debug('' + this.indent++ + ':starting parsing with stoppers ' + stoppers.join(', '));
while (this.token_list.length) {
if (stoppers.indexOf(this.token_list[0].type) > -1) {
- //sys.debug('' + this.indent-- + ':parse done returning at ' + token[0] + ' (length: ' + node_list.length + ')');
+ //util.debug('' + this.indent-- + ':parse done returning at ' + token[0] + ' (length: ' + node_list.length + ')');
return node_list;
}
token = this.next_token();
- //sys.debug('' + this.indent + ': ' + token);
+ //util.debug('' + this.indent + ': ' + token);
tag = this.tags[token.type];
if (tag && typeof tag === 'function') {
@@ -275,7 +276,7 @@ process.mixin(Parser.prototype, {
throw new parser_error('Tag not found: ' + stoppers.join(', '));
}
- //sys.debug('' + this.indent-- + ':parse done returning end (length: ' + node_list.length + ')');
+ //util.debug('' + this.indent-- + ':parse done returning end (length: ' + node_list.length + ')');
return node_list;
},
@@ -304,7 +305,7 @@ function Context(o) {
this.filters = require('./template_defaults').filters;
}
-process.mixin(Context.prototype, {
+mixin(Context.prototype, {
get: function (name) {
if (typeof name !== 'string') { return name; }
@@ -331,7 +332,7 @@ process.mixin(Context.prototype, {
if (typeof val === 'function') {
return val();
- } else {
+ } else {
return val;
}
}
@@ -358,7 +359,7 @@ function Template(input) {
this.node_list = parser.parse();
}
-process.mixin(Template.prototype, {
+mixin(Template.prototype, {
render: function (o, callback) {
if (!callback) { throw 'template.render() must be called with a callback'; }
@@ -1,6 +1,6 @@
-var sys = require('sys');
-process.mixin(GLOBAL, require('../utils/test').dsl);
-process.mixin(GLOBAL, require('./template'));
+var mixin = require('../utils/mixin').mixin;
+mixin(GLOBAL, require('../utils/test').dsl);
+mixin(GLOBAL, require('./template'));
testcase('Test tokenizer');
test('sanity test', function () {
@@ -27,7 +27,7 @@ testcase('Test tokenizer');
testcase('Filter Expression tests');
test('should parse valid syntax', function () {
- assertEquals(
+ assertEquals(
{ variable: 'item', filter_list: [ { name: 'add' } ] },
new FilterExpression("item|add")
);
Oops, something went wrong.