Added '_path' to routes so you say Routes.bookings_path() instead of Routes.booking()

This commit is contained in:
Adam Davies 2009-06-10 14:53:58 +09:30
parent ab7f7f1b53
commit 3c50f3c5ce

View file

@ -196,7 +196,7 @@
protocol: window.location.protocol+'//', protocol: window.location.protocol+'//',
host: window.location.hostname host: window.location.hostname
}; };
Routes.extractNamed = function(){ Routes.extractNamed = function(){
var route; var route;
for (var i = 0; i < this.length; i++) { for (var i = 0; i < this.length; i++) {
@ -204,20 +204,20 @@
if (route.name) { if (route.name) {
this.named.push(route); this.named.push(route);
this.named[route.name] = route; this.named[route.name] = route;
this[route.name] = (function(route){ this[route.name + '_path'] = (function(route){
var fn = function(){ var fn = function(){
var params = {}, var params = {},
options = {}, options = {},
count; count;
//Add defaults from route //Add defaults from route
for (var p in route.params) { for (var p in route.params) {
if (route.params.hasOwnProperty(p) && route.params[p].constructor !== RegExp) { if (route.params.hasOwnProperty(p) && route.params[p].constructor !== RegExp) {
params[p] = route.params[p]; params[p] = route.params[p];
} }
} }
//Allows Routes.name('foo', 'bar', {opts}) or Routes.name({foo:'foo', bar:'bar'}, {opts}) //Allows Routes.name('foo', 'bar', {opts}) or Routes.name({foo:'foo', bar:'bar'}, {opts})
if (typeof arguments[0] === 'object' && !(arguments[0] instanceof Array)) { if (typeof arguments[0] === 'object' && !(arguments[0] instanceof Array)) {
extend(params, arguments[0]); extend(params, arguments[0]);
@ -226,7 +226,7 @@
if (typeof arguments[arguments.length-1] === 'object') { if (typeof arguments[arguments.length-1] === 'object') {
options = arguments[arguments.length-1]; options = arguments[arguments.length-1];
} }
var count = 0; var count = 0;
for (var i=0; i < route.segments.length; i++) { for (var i=0; i < route.segments.length; i++) {
if (route.segments[i].isDynamic()) { if (route.segments[i].isDynamic()) {
@ -235,7 +235,7 @@
} }
} }
} }
return route.generate(params, options); return route.generate(params, options);
}; };