Permalink
Browse files

Merge branch 'master' of github.com:joshbuddy/sherpa

  • Loading branch information...
2 parents aeb4886 + 477fbf8 commit 3f2b6c5bf5554285904af344812ef22d3c660e20 @joshbuddy committed Jul 31, 2010
Showing with 30 additions and 4 deletions.
  1. +29 −3 lib/sherpa/connect.js
  2. +1 −1 package.json
View
@@ -8,6 +8,15 @@ Sherpa.Connect = function () {
Sherpa.Router.call(this)
};
+function getMatched(groups){
+ var matched =[];
+ for (i in groups){
+ matched.push(groups[i].join("/"));
+ }
+ return "/" + matched.join("/");
+}
+
+
Sherpa.Connect.prototype = new Sherpa.Router();
var proto = Sherpa.Connect.prototype;
@@ -36,7 +45,7 @@ for(i in _methods){
addRouteMethod(_meth);
}
-proto.ANY = function(path, opts){
+proto.ANY = function(path, opts, fn){
if (!fn){
fn = opts;
opts = undefined;
@@ -50,11 +59,28 @@ proto.ANY = function(path, opts){
proto.connect = function() {
var self = this
return function(httpRequest, httpResponse, next) {
- var requestUrl = url.parse(httpRequest.url);
+ var requestUrl = url.parse(httpRequest.url)
var response = self.recognize(requestUrl.pathname, httpRequest);
if (response) {
+
+ if(response.route.partial){
+ var matched = getMatched(response.path.groups);
+ httpRequest.url = httpRequest.url.replace(matched, "");
+
+ if(httpRequest.url == "")
+ httpRequest.url = "/";
+
+ httpRequest.scriptName = httpRequest.scriptName || '';
+ httpRequest.scriptName = httpRequest.scriptName + matched
+ }
+
httpRequest.sherpaResponse = response;
- response.destination(httpRequest, httpResponse, next);
+
+ if(response.destination.handle){
+ response.destination.handle(httpRequest, httpResponse, next);
+ } else {
+ response.destination(httpRequest, httpResponse, next);
+ }
} else {
next();
}
View
@@ -2,7 +2,7 @@
"name": "sherpa",
"description": "Simple URI routing in Javascript",
"author": "Joshua Hull <joshbuddy@gmail.com>",
- "version": "0.1.0",
+ "version": "0.1.1",
"directories": {
"lib" : "./lib/sherpa"
},

0 comments on commit 3f2b6c5

Please sign in to comment.