Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed all of the issue that came with the API changes in recent Node.…

…js commits.

Also fixed a couple bugs along the way.
  • Loading branch information...
commit 27f4fb340dd9074035972ad16635e2007fa9fba1 1 parent 5313703
RayMorgan authored
View
1  .gitignore
@@ -0,0 +1 @@
+v8.log
View
12 lib/vroom.js
@@ -1,13 +1,13 @@
+var path = require('path');
+
var Vroom = {};
-__module.exports = Vroom;
-node.mixin(Vroom, require('vroom/loader.js'));
+module.exports = Vroom;
+
+process.mixin(Vroom, require('./vroom/loader'));
Vroom.version = "0.5";
Vroom.PASS = "PASS";
-// Vroom.Hooks(Vroom.Application);
-// Vroom.Hooks(Vroom.PathResource);
-
Vroom.installPlugin = function (plugin) {
if (typeof(plugin) == "function") {
plugin(Vroom);
@@ -17,5 +17,5 @@ Vroom.installPlugin = function (plugin) {
}
Vroom.require = function (path) {
- return require(node.path.join(node.path.dirname(__filename), path));
+ return require(path.join(path.dirname(__filename), path));
}
View
4 lib/vroom/application.js
@@ -1,5 +1,5 @@
-var Vroom = __module.parent.exports.Vroom;
-var Hooks = require('hooks.js').Hooks;
+var Vroom = module.parent.exports.Vroom;
+var Hooks = require('./hooks').Hooks;
/**
* Constructor for a Vroom.Application. This is responsible for
View
9 lib/vroom/config.js
@@ -1,6 +1,7 @@
-var Vroom = __module.parent.exports.Vroom;
-var utils = require("/utils.js");
-var print = utils.print;
+var Vroom = module.parent.exports.Vroom;
+var path = require('path');
+var sys = require("sys");
+var print = sys.print;
/**
* Constructor for the Vroom.Config class. This class is responsible
@@ -100,7 +101,7 @@ exports.Config.prototype = {
*/
set root(path) {
if (/\.[^./]+$/.exec(path))
- this._root = node.path.dirname(path);
+ this._root = path.dirname(path);
else
this._root = path;
},
View
16 lib/vroom/loader.js
@@ -1,9 +1,9 @@
-exports.Vroom = __module.parent.exports;
+exports.Vroom = module.parent.exports;
-exports.Application = require('application.js').Application;
-exports.Config = require('config.js').Config;
-exports.Exceptions = require('exceptions.js');
-exports.Hooks = require('hooks.js').Hooks;
-exports.Logger = require('logger.js').Logger;
-exports.Request = require('request.js').Request;
-exports.Server = require('server.js').Server;
+exports.Application = require('./application').Application;
+exports.Config = require('./config').Config;
+exports.Exceptions = require('./exceptions');
+exports.Hooks = require('./hooks').Hooks;
+exports.Logger = require('./logger').Logger;
+exports.Request = require('./request').Request;
+exports.Server = require('./server').Server;
View
4 lib/vroom/logger.js
@@ -1,4 +1,4 @@
-var utils = require("/utils.js");
+var sys = require("sys");
exports.Logger = function Logger(startingLevel) {
this._level = levels[startingLevel] || 1;
@@ -107,5 +107,5 @@ function log(level, args) {
buffer += args[i];
else
buffer += JSON.stringify(args[i]);
- utils.puts(buffer);
+ sys.puts(buffer);
}
View
22 lib/vroom/path_resource.js
@@ -1,10 +1,10 @@
-var Hooks = require('hooks.js').Hooks;
-var Route = require('path_resource/route.js');
+var Hooks = require('./hooks').Hooks;
+var Route = require('./path_resource/route');
var DEFAULT_METHODS = ['get', 'post', 'put', 'delete', 'head'];
-__module.exports = function PathResource(callback, extraMethods) {
+module.exports = function PathResource(callback, extraMethods) {
extraMethods = extraMethods || [];
this.routes = {};
this.methods = [];
@@ -16,7 +16,7 @@ __module.exports = function PathResource(callback, extraMethods) {
callback.call(this, this);
};
-var PathResource = __module.exports;
+var PathResource = module.exports;
PathResource.prototype = {
addMethod: function (method) {
@@ -121,19 +121,21 @@ PathResource.prototype = {
var fun = eval("(" + code + ")");
- routeFor[method] = function (path, request) {
- var res = fun(callbacks, path, request);
- return res;
- };
+ (function (fun, callbacks) {
+ routeFor[method] = function (path, request) {
+ var res = fun(callbacks, path, request);
+ return res;
+ };
+ })(fun, callbacks);
}
- var resource = this.hook('after_compile', [function () {
+ var resource = function () {
var ret;
if (routeFor[this.method] && (ret = routeFor[this.method](this.path, this)) !== 'PASS')
return ret;
else
return 'PASS';
- }]);
+ };
return resource;
}
}
View
10 lib/vroom/plugin/ejs.js
@@ -1,11 +1,13 @@
+var posix = require('posix');
+
exports.install = function install(Vroom) {
Vroom.Config.addOption('viewDir', "The directory views are served from.", ['{String}']);
Vroom.Config.addOption('reloadTemplates', "Reload templates on each request, great for development.", ['false', 'true']);
Vroom.Request.prototype.ejs = function (name, opts) {
opts = opts || {};
- var promise = new node.Promise();
- var renderPromise = new node.Promise();
+ var promise = new process.Promise();
+ var renderPromise = new process.Promise();
var r = this;
var config = this.application.config;
var path;
@@ -43,9 +45,9 @@ exports.install = function install(Vroom) {
var cache = {};
function compile(path) {
- var promise = new node.Promise();
+ var promise = new process.Promise();
- var cat_promise = node.fs.cat(path, "binary");
+ var cat_promise = posix.cat(path, "binary");
cat_promise.addCallback(function (contents) {
var tmpl = compile_string(contents);
View
4 lib/vroom/request.js
@@ -1,5 +1,5 @@
-var Vroom = __module.parent.exports.Vroom;
-var Exceptions = require('exceptions.js');
+var Vroom = module.parent.exports.Vroom;
+var Exceptions = require('./exceptions');
/**
* Creates a new Request instance
View
4 lib/vroom/server.js
@@ -1,4 +1,4 @@
-var Vroom = __module.parent.exports.Vroom;
+var Vroom = module.parent.exports.Vroom;
/**
* Constructor for the Vroom.Server. The server is a thin wrapper over
@@ -19,7 +19,7 @@ exports.Server = function Server(callback, opts) {
this.application = opts.application || {};
var self = this;
- this.server = require("/http.js").createServer(function (req, res) {
+ this.server = require("http").createServer(function (req, res) {
var r = new Vroom.Request(self.application, req, res);
return callback.call(self.application, r);
});
View
13 test/app/boot.js
@@ -1,5 +1,6 @@
-var Vroom = require('../../lib/vroom.js');
-Vroom.installPlugin(require('../../lib/vroom/plugin/ejs.js'));
+var path = require('path');
+var Vroom = require('../../lib/vroom');
+Vroom.installPlugin(require('../../lib/vroom/plugin/ejs'));
var app = new Vroom.Application();
@@ -7,14 +8,14 @@ var app = new Vroom.Application();
Vroom.Config.printOptions();
app.config.use(function (c) {
- c['viewDir'] = node.path.dirname(__filename);
+ c['viewDir'] = path.dirname(__filename);
c['reloadTemplates'] = true;
});
-var root = require('root.js');
-var posts = require('posts.js');
-var exceptions = require('exceptions.js');
+var root = require('./root');
+var posts = require('./posts');
+var exceptions = require('./exceptions');
app.mount('root', '/', root);
app.mount('posts', '/posts', posts);
View
2  test/app/posts.js
@@ -1,4 +1,4 @@
-var PathResource = require('../../lib/vroom/path_resource.js');
+var PathResource = require('../../lib/vroom/path_resource');
exports.resource = new PathResource(function (r) {
View
2  test/app/root.js
@@ -1,4 +1,4 @@
-var PathResource = require('../../lib/vroom/path_resource.js');
+var PathResource = require('../../lib/vroom/path_resource');
exports.resource = new PathResource(function (r) {
View
4 test/mjsunit/test_nested_params.js
@@ -1,5 +1,5 @@
-var helpers = require('../test_helpers.js');
-var params = require("../../lib/vroom/plugin/nested_params.js");
+var helpers = require('../test_helpers');
+var params = require("../../lib/vroom/plugin/nested_params");
var matchMap = [
[ "foo=bar", {foo: 'bar'} ],
View
8 test/mjsunit/test_request.js
@@ -1,12 +1,12 @@
-var helpers = require("../test_helpers.js");
+var helpers = require("../test_helpers");
var assertMatch = helpers.assertMatch;
// Setup the Mocks
-var MockReq = require("mock/req.js");
-var MockRes = require("mock/res.js");
+var MockReq = require("./mock/req");
+var MockRes = require("./mock/res");
exports.beforeEach = function () {
- var Vroom = require('../../lib/vroom.js');
+ var Vroom = require('../../lib/vroom');
this.req = MockReq.mock({
path: "/people",
View
12 test/mjsunit/test_resource.js
@@ -1,13 +1,13 @@
-var PathResource = require("../../lib/vroom/path_resource.js");
-var helpers = require("../test_helpers.js");
+var PathResource = require("../../lib/vroom/path_resource");
+var helpers = require("../test_helpers");
var assertMatch = helpers.assertMatch;
-var MockReq = require("mock/req.js");
-var MockRes = require("mock/res.js");
-var MockLog = require("mock/logger.js");
+var MockReq = require("./mock/req");
+var MockRes = require("./mock/res");
+var MockLog = require("./mock/logger");
exports.beforeEach = function () {
- var Vroom = require('../../lib/vroom.js');
+ var Vroom = require('../../lib/vroom');
this.req = MockReq.mock();
this.res = MockRes.mock();
View
4 test/mjsunit/test_route.js
@@ -1,7 +1,7 @@
-var helpers = require("../test_helpers.js");
+var helpers = require("../test_helpers");
var assertMatch = helpers.assertMatch;
-var Route = require("../../lib/vroom/path_resource/route.js");
+var Route = require("../../lib/vroom/path_resource/route");
var routeMap = [
{ route: "/", compiled: [{route: "/^\\/?\\??$/", params: {}}] },
View
2  test/test_helpers.js
@@ -1,4 +1,4 @@
-node.mixin(require("/mjsunit.js"));
+process.mixin(require("mjsunit"));
exports.assertMatch = function assertMatch(o1, o2) {
assertEquals(
View
47 test/test_suite.js
@@ -1,18 +1,23 @@
-node.mixin(require("/mjsunit.js"));
+var path = require('path');
+var posix = require('posix');
-var rootPath = "./" + node.path.dirname(__filename).replace(node.cwd(), "") + "/mjsunit/";
-var contents = node.fs.readdir(rootPath).wait();
+process.mixin(require("mjsunit"));
+
+process.chdir(path.dirname(__filename));
+
+var rootPath = path.join(process.cwd(), "/mjsunit/");
+var contents = posix.readdir(rootPath).wait();
var tests = [];
var successful = 0;
var errors = [];
-node.stdio.writeError("Running Vroom Test Suite\n\n");
+process.stdio.writeError("Running Vroom Test Suite\n\n");
contents.forEach(function (filename) {
file = rootPath + filename;
- var stat = node.fs.stat(file).wait();
+ var stat = posix.stat(file).wait();
if (stat.isFile() && /^test_/.exec(filename)) {
- tests.push(require("mjsunit/" + filename));
+ tests.push(require(rootPath + filename.replace(/\.js$/, "")));
}
});
@@ -36,10 +41,10 @@ tests.forEach(function (t) {
if (typeof(t) == "function") {
t();
}
- node.stdio.writeError(".");
+ green(".");
successful++;
} catch (e) {
- node.stdio.writeError("f");
+ red("f");
errors.push(e);
}
});
@@ -49,19 +54,35 @@ tests.forEach(function (t) {
process.addListener('exit', function () {
printErrors(errors);
- node.stdio.writeError("\n\n" + successful + " Passed, " + errors.length + " Failures\n");
+ write("\n\n")
+ if (successful) green(successful + " Passed");
+ if (successful && errors.length) write(", ");
+ if (errors.length) red(errors.length + " Failures");
+ write("\n");
});
function printErrors(errors) {
for (var i = 0; i < errors.length; i++) {
var e = errors[i];
- node.stdio.writeError("\n\n");
+ write("\n\n");
if (e.stack) {
- node.stdio.writeError(e.stack);
+ write(e.stack);
} else if (e.message) {
- node.stdio.writeError(e.message);
+ write(e.message);
} else {
- node.stdio.writeError(e);
+ write(e);
}
}
}
+
+function write(str) {
+ process.stdio.writeError(str);
+}
+
+function green(str) {
+ process.stdio.writeError('\033[32m' + str + '\033[0m');
+}
+
+function red(str) {
+ process.stdio.writeError('\033[31m' + str + '\033[0m');
+}
Please sign in to comment.
Something went wrong with that request. Please try again.