Skip to content
Browse files

removed debug

  • Loading branch information...
1 parent efa33da commit 01da3ebf429286691badb1b4bf80fac680659217 @joshbuddy committed Jul 1, 2010
Showing with 1 addition and 93 deletions.
  1. +0 −87 lib/sherpa.js
  2. +1 −1 spec/run.sh
  3. +0 −5 spec/spec_recognize.js
View
87 lib/sherpa.js
@@ -20,10 +20,6 @@ Sherpa = {
},
Path: function(route, uri) {
this.route = route;
- var sys = require('sys');
-
- sys.debug(sys.inspect(uri));
-
var regex = /(\/|:[a-zA-Z0-9_]+|(?:\\:|[^:\/]+)*)/;
var splitUri = uri.split(regex);
@@ -44,16 +40,13 @@ Sherpa = {
for (var splitIndex = 0; splitIndex < splitUri.length; splitIndex++) {
var part = splitUri[splitIndex];
if (part == '/') {
- sys.debug('adding new group');
this.groups.push([]);
} else if (part != '') {
- sys.debug('pushing to last group');
this.groups[this.groups.length - 1].push(part);
}
}
},
Route: function(router, uri) {
- var sys = require('sys');
this.router = router;
this.requestConditions = {};
this.matchingConditions = {};
@@ -87,18 +80,13 @@ Sherpa = {
this.partial = false;
this.paths = [];
for (var pathsIdx = 0; pathsIdx != paths.length; pathsIdx++) {
- sys.debug("ADDING PATH "+paths[pathsIdx]);
this.paths.push(new Sherpa.Path(this, paths[pathsIdx]));
}
},
Node: function() {
this.reset();
},
Response: function(path, params) {
- var sys = require('sys');
-
- sys.debug("path --> "+sys.inspect(path));
-
this.path = path
this.route = path.route;
this.paramsArray = params;
@@ -152,38 +140,27 @@ Sherpa.Node.prototype = {
return this.requestNode;
},
find: function(parts, request, params) {
- var sys = require('sys');
- sys.debug("find on parts: " + sys.inspect(parts) + " with params: "+sys.inspect(params)+" partial?"+(this.destination && this.destination.route.partial));
if (this.requestNode || this.destination && this.destination.route.partial) {
- sys.debug("potential partial match");
var target = this;
if (target.requestNode) {
- sys.debug("partial match has a request node");
target = target.requestNode.findRequest(request);
}
- sys.debug("finally testing the destination");
if (target && target.destination && target.destination.route.partial) {
- sys.debug("yup, we have one");
return new Sherpa.Response(target.destination, params);
- } else {
- sys.debug("nope, movign on");
}
}
if (parts.length == 0) {
var target = this;
if (this.requestNode) {
- sys.debug("there is a request node here..");
target = this.requestNode.findRequest(request);
}
- if (target) sys.debug("destination?: " + sys.inspect(target.destination));
return target && target.destination ? new Sherpa.Response(target.destination, params) : undefined;
} else {
if (this.linear.length != 0) {
var wholePath = parts.join('/');
for (var linearIdx = 0; linearIdx != this.linear.length; linearIdx++) {
var lin = this.linear[linearIdx];
var match = lin[0].exec(wholePath);
- sys.debug("matched:"+sys.inspect(match));
if (match) {
matchedIndex = match.shift().length;
var resplitParts = wholePath.substring(matchedIndex).split('/');
@@ -206,16 +183,11 @@ Sherpa.Node.prototype = {
return undefined;
},
findRequest: function(request) {
- var sys = require('sys');
if (this.requestMethod) {
- sys.debug("there is a request method: " + this.requestMethod);
- sys.debug("the current request has: " + request[this.requestMethod]);
if (this.linear.length != 0 && request[this.requestMethod]) {
- sys.debug("doing a linear search");
for (var linearIdx = 0; linearIdx != this.linear.length; linearIdx++) {
var lin = this.linear[linearIdx];
var match = lin[0].exec(request[this.requestMethod]);
- sys.debug("matched:"+sys.inspect(match));
if (match) {
matchedIndex = match.shift().length;
var potentialMatch = lin[2].findRequest(request);
@@ -224,66 +196,38 @@ Sherpa.Node.prototype = {
}
}
if (request[this.requestMethod] && this.lookup[request[this.requestMethod]]) {
- sys.debug("doing a lookup search");
var potentialMatch = this.lookup[request[this.requestMethod]].findRequest(request);
if (potentialMatch) {
- sys.debug("found one..");
return potentialMatch;
}
}
if (this.catchall) {
- sys.debug("doing a catchall search");
return this.catchall.findRequest(request);
}
- sys.debug("no search succeeded");
} else if (this.destination) {
- sys.debug("there is a destination");
return this;
} else {
- sys.debug("we got nothin'");
return undefined;
}
},
transplantValue: function() {
- var sys = require('sys');
- sys.debug("transplantValue this.destination:..." + sys.inspect(this.destination));
- sys.debug("transplantValue this.requestNode:..." + sys.inspect(this.requestNode));
if (this.destination && this.requestNode) {
- sys.debug("there is a destination");
var targetNode = this.requestNode;
while (targetNode.requestMethod) {
- sys.debug("adding a catchall");
targetNode = (targetNode.addCatchall());
}
- sys.debug("re-applying destination");
targetNode.destination = this.destination;
this.destination = undefined;
- } else {
- sys.debug("there is NOT a destination");
- sys.debug(sys.inspect(this.requestNode));
}
- sys.debug("done transplantValue...");
},
compileRequestConditions: function(router, requestConditions) {
- var sys = require('sys');
- //raise(UnsupportedRequestConditionError.new) if (request_options.keys & RequestNode::RequestMethods).size != request_options.size
var currentNodes = [this];
var requestMethods = router.requestKeys;
-
- sys.debug("compiling for these request conditions: "+sys.inspect(requestConditions));
for (var requestMethodIdx in requestMethods) {
var method = requestMethods[requestMethodIdx];
- sys.debug("looking at method: "+method);
-
if (requestConditions[method]) {// so, the request method we care about it ..
-
- sys.debug("we care about this method " + sys.inspect(requestConditions[method]));
-
if (currentNodes.length == 1 && currentNodes[0] === this) {
- sys.debug("currentNodes is in the initial state");
currentNodes = [this.addRequestNode()];
- } else {
- sys.debug("currentNodes is NOT in the initial state");
}
for (var currentNodeIndex = 0; currentNodeIndex != currentNodes.length; currentNodeIndex++) {
@@ -296,35 +240,25 @@ Sherpa.Node.prototype = {
var currentPosition = requestMethods.indexOf(currentNode.requestMethod);
if (masterPosition == currentPosition) {
- sys.debug("doing a lookup add on "+method+" "+requestConditions[method]);
-
if (requestConditions[method].compile) {
currentNodes[currentNodeIndex] = currentNodes[currentNodeIndex].addLinear(requestConditions[method], 0);
} else {
currentNodes[currentNodeIndex] = currentNodes[currentNodeIndex].addLookup(requestConditions[method]);
}
} else if (masterPosition < currentPosition) {
- sys.debug("adding to the catchall");
currentNodes[currentNodeIndex] = currentNodes[currentNodeIndex].addCatchall();
} else {
- sys.debug("got no where to go...");
var nextNode = currentNode.dup();
currentNode.reset();
currentNode.requestMethod = method;
currentNode.catchall = nextNode;
currentNodeIndex--;
}
}
- sys.debug("all done");
-
- //current_nodes.flatten!
} else {
- sys.debug("we don't care about this method");
for (var currentNodeIndex = 0; currentNodeIndex != currentNodes.length; currentNodeIndex++) {
- sys.debug("examining node "+currentNodeIndex);
var node = currentNodes[currentNodeIndex];
if (!node.requestMethod && node.requestNode) {
- sys.debug("using the requestNode");
node = node.requestNode;
}
if (node.requestMethod) {
@@ -387,7 +321,6 @@ Sherpa.Route.prototype = {
return this;
},
generate: function(params) {
- var sys = require('sys');
var path = undefined;
if (params == undefined || this.paths.length == 1) {
path = this.paths[0].generate(params);
@@ -398,10 +331,7 @@ Sherpa.Route.prototype = {
}
}
- sys.debug("path is: "+sys.inspect(path));
if (path) {
- sys.debug("params are now: "+sys.inspect(params));
-
path = encodeURI(path);
var query = '';
for (var key in params) {
@@ -416,42 +346,27 @@ Sherpa.Route.prototype = {
Sherpa.Path.prototype = {
generate: function(params) {
- var sys = require('sys');
- sys.debug("path generate for "+sys.inspect(params) + " from "+sys.inspect(this.variableNames));
for(var varIdx = 0; varIdx != this.variableNames.length; varIdx++) {
if (!params[this.variableNames[varIdx]]) return undefined;
}
- sys.debug("passed for "+sys.inspect(params));
for(var varIdx = 0; varIdx != this.variableNames.length; varIdx++) {
- sys.debug("testing: "+this.variableNames[varIdx] + " --> " + this.route.matchingConditions[this.variableNames[varIdx]]);
if (this.route.matchingConditions[this.variableNames[varIdx]]) {
if (this.route.matchingConditions[this.variableNames[varIdx]].exec(params[this.variableNames[varIdx]].toString()) != params[this.variableNames[varIdx]].toString()) {
- sys.debug("regex exec didn't work...");
return undefined;
- } else {
- sys.debug("regex exec worked");
}
- } else {
- sys.debug("matchesWith doesn't exist...");
}
}
var path = eval(this.compiledUri);
for(var varIdx = 0; varIdx != this.variableNames.length; varIdx++) {
delete params[this.variableNames[varIdx]];
}
- sys.debug("left with params "+sys.inspect(params));
return path;
},
compile: function() {
- var sys = require('sys');
- sys.debug("groups:"+sys.inspect(this.groups));
-
this.variableNames = [];
var currentNode = this.route.router.root;
for(var groupIdx = 0; groupIdx != this.groups.length; groupIdx++) {
var group = this.groups[groupIdx];
- sys.debug(groupIdx);
- sys.debug(sys.inspect(group));
if (group.length > 1) {
var pattern = '^';
for (var partIndex = 0; partIndex != group.length; partIndex++) {
@@ -466,7 +381,6 @@ Sherpa.Path.prototype = {
pattern += RegExp.escape(part);
}
}
- sys.debug("PATTERN:" + sys.inspect(pattern));
currentNode = currentNode.addLinear(new RegExp(pattern), captureCount);
} else if (group.length == 1) {
var part = group[0];
@@ -485,7 +399,6 @@ Sherpa.Path.prototype = {
}
var nodes = currentNode.compileRequestConditions(this.route.router, this.route.requestConditions);
for (var nodeIdx = 0; nodeIdx != nodes.length; nodeIdx++) {
- sys.debug("adding a destination to " + sys.inspect(nodes[nodeIdx]));
nodes[nodeIdx].destination = this;
}
}
View
2 spec/run.sh
@@ -1,4 +1,4 @@
#!/bin/sh
node spec/spec_generate.js
-#node spec/spec_recognize.js
+node spec/spec_recognize.js
View
5 spec/spec_recognize.js
@@ -10,18 +10,13 @@ minitest.context("Sherpa#recognize()", function () {
this.assertion("should recognize a simple route", function(test) {
this.router.add('/').to('recognized');
- var sys = require('sys');
var resposne = this.router.recognize('/');
- sys.debug("RESPONSE!: "+ sys.inspect(resposne.destination));
- assert.equal('recognized', this.router.recognize('/').destination);
test.finished();
});
this.assertion("should recognize a simple route", function(test) {
this.router.add('/test').to('recognized');
- var sys = require('sys');
var resposne = this.router.recognize('/test');
- sys.debug("RESPONSE!: "+ sys.inspect(resposne.destination));
assert.equal('recognized', this.router.recognize('/test').destination);
test.finished();
});

0 comments on commit 01da3eb

Please sign in to comment.
Something went wrong with that request. Please try again.