Permalink
Browse files

add support for multiple matches

  • Loading branch information...
1 parent 7121c44 commit 0672b9a4841b1389107e598cbfb637bcf2600bed @haggen committed Aug 24, 2012
Showing with 17 additions and 17 deletions.
  1. +14 −14 way.js
  2. +3 −3 way.min.js
View
28 way.js
@@ -1,5 +1,5 @@
/*
- * WayJS v0.1.0 2012-08-21 10:58:17 -0300
+ * WayJS v0.2.0 2012-08-23 22:44:15 -0300
* by Arthur Corenzan <arthur@corenzan.com>
* licensed under http://creativecommons.org/licenses/by/3.0
* more on http://haggen.github.com/wayjs
@@ -12,8 +12,6 @@
Way = function() {
this.routes = [];
- this.hooks = {};
- this.params = {};
};
Way.prototype = {
@@ -52,27 +50,29 @@
return '(.+?)';
});
- return new RegExp('^' + re + '$');
+ return new RegExp('^' + re);
},
match: function(path) {
- var way, route, match, i, j;
+ var route, match, matches, m, i, j;
- way = this;
- way.params = [];
+ matches = [];
- for(i = 0; i < way.routes.length; i++) {
- route = way.routes[i];
- match = path.match(route.pattern);
+ for(i = 0; i < this.routes.length; i++) {
+ route = this.routes[i];
+ match = { action: route.action, params: [] };
+ m = path.match(route.pattern);
- if(match) {
- for(j = 1; j < match.length; j++) {
- way.params[route.params[j - 1]] = match[j];
+ if(m) {
+ for(j = 1; j < m.length; j++) {
+ match.params[route.params[j - 1]] = m[j];
}
- return route.action;
+ matches.push(match);
}
}
+
+ return matches;
}
};
View
@@ -1,8 +1,8 @@
/*
- * WayJS v0.1.0 2012-08-21 10:58:17 -0300
+ * WayJS v0.2.0 2012-08-23 22:44:15 -0300
* by Arthur Corenzan <arthur@corenzan.com>
* licensed under http://creativecommons.org/licenses/by/3.0
* more on http://haggen.github.com/wayjs
*/
-(function(){var c;c=function(){this.routes=[];this.hooks={};this.params={}};c.prototype={map:function(b,d){var a={params:[]};a.action=d;a.pattern=this.translate(b,a);this.routes.push(a)},translate:function(b,d){var a;a=b.replace(/\//g,"\\/");a=a.replace(/\)/g,function(){return")?"});a=a.replace(/:(\w[\w\d]*)|\(/g,function(a,b){d.params.push("("===a?"_":b);return"("===a?"(":"([^\\/]+?)"});a=a.replace(/\*/g,function(){d.params.push("splat");return"(.+?)"});return RegExp("^"+a+"$")},match:function(b){var d,
-a,c;this.params=[];for(c=0;c<this.routes.length;c++)if(d=this.routes[c],a=b.match(d.pattern)){for(b=1;b<a.length;b++)this.params[d.params[b-1]]=a[b];return d.action}}};"undefined"===typeof window?module.exports=new c:window.way=new c})();
+(function(){var c;c=function(){this.routes=[]};c.prototype={map:function(d,b){var a={params:[]};a.action=b;a.pattern=this.translate(d,a);this.routes.push(a)},translate:function(d,b){var a;a=d.replace(/\//g,"\\/");a=a.replace(/\)/g,function(){return")?"});a=a.replace(/:(\w[\w\d]*)|\(/g,function(a,d){b.params.push("("===a?"_":d);return"("===a?"(":"([^\\/]+?)"});a=a.replace(/\*/g,function(){b.params.push("splat");return"(.+?)"});return RegExp("^"+a)},match:function(d){var b,a,c,g,f,e;c=[];for(f=0;f<
+this.routes.length;f++)if(b=this.routes[f],a={action:b.action,params:[]},g=d.match(b.pattern)){for(e=1;e<g.length;e++)a.params[b.params[e-1]]=g[e];c.push(a)}return c}};"undefined"===typeof window?module.exports=new c:window.way=new c})();

0 comments on commit 0672b9a

Please sign in to comment.