Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added prefixed clone

  • Loading branch information...
commit 4b52cd9940f0443ac1d878e67c5d4f51ca889842 1 parent f6fb253
@1602 authored
Showing with 25 additions and 1 deletion.
  1. +17 −1 lib/railway_routes.js
  2. +8 −0 test/routes.test.js
View
18 lib/railway_routes.js
@@ -46,7 +46,19 @@ function Map(app, bridge) {
this.nestedRoutesOnCollection = false;
}
-function RoutesCollection() {
+function RoutesCollection(origin, prefix) {
+ var self = this;
+ if (origin) {
+ for (var name in origin) {
+ this[name] = function() {
+ var args = Array.prototype.slice.call(arguments);
+ return '/' + prefix + origin[name].apply(origin, args);
+ };
+ this[name].toString = function() {
+ return self[name]();
+ };
+ }
+ }
}
/**
@@ -547,6 +559,10 @@ Map.prototype.collection = function (actions) {
return this;
};
+Map.prototype.clone = function clone(prefix) {
+ return new RoutesCollection(this.pathTo, prefix);
+};
+
function camelize(str) {
if (!str) return str;
return str.replace(/_+(.)/g, function (all, first) {
View
8 test/routes.test.js
@@ -248,3 +248,11 @@ test('should be optional to specify controller#action', function () {
paths[1][1].should.equal('/posts/destroyAll');
paths[1][2].should.equal('posts#destroyAll');
});
+
+test('should clone object with prefix', function() {
+ map.get('/test/url', 'test#url', {as: 'testUrl'});
+ var clone = map.clone('prefix');
+ map.pathTo.testUrl().should.equal('/test/url');
+ map.pathTo.testUrl().should.equal('/test/url');
+ clone.testUrl().should.equal('/prefix/test/url');
+});
Please sign in to comment.
Something went wrong with that request. Please try again.