Permalink
Browse files

Merge branch 'file-path'

  • Loading branch information...
2 parents f394dfb + ffa5ee4 commit 8053757f23dcc2462a2063963e44101a87e7a34f @mbostock mbostock committed Oct 5, 2011
Showing with 40 additions and 31 deletions.
  1. +2 −1 lib/cube/index.js
  2. +3 −7 lib/cube/server/endpoint.js
  3. +30 −19 lib/cube/server/visualizer.js
  4. +2 −2 package.json
  5. +3 −2 test/endpoint-test.js
View
@@ -1,6 +1,7 @@
-exports.version = "0.0.5";
+exports.version = "0.0.6";
exports.emitter = require("./server/emitter");
exports.server = require("./server/server");
exports.collector = require("./server/collector");
exports.evaluator = require("./server/evaluator");
exports.visualizer = require("./server/visualizer");
+exports.endpoint = require("./server/endpoint");
@@ -30,7 +30,7 @@ function re(re, dispatch) {
}
function file() {
- var files = Array.prototype.map.call(arguments, resolve),
+ var files = Array.prototype.slice.call(arguments),
type = types[files[0].substring(files[0].lastIndexOf(".") + 1)];
return function(request, response) {
var modified = -Infinity,
@@ -39,7 +39,7 @@ function file() {
files.forEach(function(file) {
fs.stat(file, function(error, stats) {
- if (error) return fiveohoh(request, response);
+ if (error) throw fiveohoh(request, response), error;
size += stats.size;
var time = new Date(stats.mtime);
if (time > modified) modified = time;
@@ -69,7 +69,7 @@ function file() {
function read(i) {
fs.readFile(files[i], "UTF-8", function(error, data) {
- if (error) return fiveohoh(request, response);
+ if (error) throw fiveohoh(request, response), error;
response.write(data);
if (i < files.length - 1) read(i + 1);
else response.end();
@@ -78,10 +78,6 @@ function file() {
};
};
-function resolve(name) {
- return path.join(__dirname, name);
-}
-
function fiveohoh(request, response) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.end("500 Server Error");
@@ -1,4 +1,5 @@
var url = require("url"),
+ path = require("path"),
endpoint = require("./endpoint");
exports.register = function(db, endpoints) {
@@ -9,28 +10,34 @@ exports.register = function(db, endpoints) {
endpoint.exact("/", createBoard(db)),
endpoint.re(/^\/[0-9][0-9a-z]{5}(\/edit)?$/, loadBoard(db)),
endpoint.exact("/cube.js", endpoint.file(
- "../client/start.js",
- "../client/cube.js",
- "../client/piece.js",
- "../client/piece-area.js",
- "../client/piece-sum.js",
- "../client/piece-text.js",
- "../client/palette.js",
- "../client/squares.js",
- "../client/board.js",
- "../client/header.js",
- "../client/end.js"
+ resolve("start.js"),
+ resolve("cube.js"),
+ resolve("piece.js"),
+ resolve("piece-area.js"),
+ resolve("piece-sum.js"),
+ resolve("piece-text.js"),
+ resolve("palette.js"),
+ resolve("squares.js"),
+ resolve("board.js"),
+ resolve("header.js"),
+ resolve("end.js")
)),
endpoint.exact("/cube.css", endpoint.file(
- "../client/body.css",
- "../client/palette.css",
- "../client/board.css",
- "../client/piece.css"
+ resolve("body.css"),
+ resolve("palette.css"),
+ resolve("board.css"),
+ resolve("piece.css")
)),
endpoint.exact("/d3/d3.js", endpoint.file(
- "../../../node_modules/d3/d3.min.js",
- "../client/semicolon.js",
- "../../../node_modules/d3/d3.time.min.js"
+ resolve("../../../node_modules/d3/d3.min.js"),
+ resolve("semicolon.js"),
+ resolve("../../../node_modules/d3/d3.geo.min.js"),
+ resolve("semicolon.js"),
+ resolve("../../../node_modules/d3/d3.geom.min.js"),
+ resolve("semicolon.js"),
+ resolve("../../../node_modules/d3/d3.layout.min.js"),
+ resolve("semicolon.js"),
+ resolve("../../../node_modules/d3/d3.time.min.js")
))
);
};
@@ -61,7 +68,7 @@ function createBoard(db) {
function loadBoard(db) {
var boards,
- file = endpoint.file("../client/visualizer.html");
+ file = endpoint.file(resolve("visualizer.html"));
db.collection("boards", function(error, collection) {
boards = collection;
@@ -173,6 +180,10 @@ function viewBoard(db) {
return dispatch;
}
+function resolve(file) {
+ return path.join(__dirname, "../client", file);
+}
+
function emit(callbacks, event) {
callbacks.forEach(function(callback) {
callback(event);
View
@@ -1,14 +1,14 @@
{
"name": "cube",
- "version": "0.0.5",
+ "version": "0.0.6",
"description": "A system for time series visualization using MongoDB, Node and D3.",
"keywords": ["time series", "visualization"],
"homepage": "http://square.github.com/cube/",
"author": {"name": "Mike Bostock", "url": "http://bost.ocks.org/mike"},
"repository": {"type": "git", "url": "http://github.com/square/cube.git"},
"main": "./lib/cube",
"dependencies": {
- "d3": "2.1.3",
+ "d3": "2.3.2",
"mongodb": "0.9.6-15",
"pegjs": "0.6.2",
"vows": "0.5.11",
View
@@ -6,8 +6,9 @@ var vows = require("vows"),
var suite = vows.describe("endpoint");
-var port = ++test.port,
- server = http.createServer(endpoint.file("../client/semicolon.js", "../client/semicolon.js"));
+var file = "lib/cube/client/semicolon.js",
+ port = ++test.port,
+ server = http.createServer(endpoint.file(file, file));
server.listen(port, "127.0.0.1");

0 comments on commit 8053757

Please sign in to comment.