crossroadsjs-rails 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Crossroads.js for Rails [![Build Status][travis_ci_build_status]][travis_ci][![Dependency Status][gemnasium_dependency_status]][gemnasium]
|
2
2
|
|
3
|
-
Provides Crossroads.js (0.
|
3
|
+
Provides Crossroads.js (0.11.0) for use with Rails 3
|
4
4
|
|
5
5
|
[RubyGems][ruby_gems] | [Ruby Toolbox][ruby_toolbox] | [GitHub][github] | [Travis CI][travis_ci] | [Gemnasium][gemnasium] | [RubyDoc][ruby_doc]
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Crossroadsjs::Rails do
|
4
|
-
it { Crossroadsjs::Rails::VERSION.should == "1.
|
5
|
-
it { Crossroadsjs::Rails::CROSSROADSJS_VERSION.should == "0.
|
4
|
+
it { Crossroadsjs::Rails::VERSION.should == "1.4.0" }
|
5
|
+
it { Crossroadsjs::Rails::CROSSROADSJS_VERSION.should == "0.11.0" }
|
6
6
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* crossroads <http://millermedeiros.github.com/crossroads.js/>
|
3
3
|
* License: MIT
|
4
4
|
* Author: Miller Medeiros
|
5
|
-
* Version: 0.
|
5
|
+
* Version: 0.11.0 (2012/10/31 21:44)
|
6
6
|
*/
|
7
7
|
|
8
8
|
(function (define) {
|
@@ -34,6 +34,13 @@ define(['signals'], function (signals) {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
+
function arrayRemove(arr, item) {
|
38
|
+
var i = arrayIndexOf(arr, item);
|
39
|
+
if (i !== -1) {
|
40
|
+
arr.splice(i, 1);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
37
44
|
function isKind(val, kind) {
|
38
45
|
return '[object '+ kind +']' === Object.prototype.toString.call(val);
|
39
46
|
}
|
@@ -81,14 +88,14 @@ define(['signals'], function (signals) {
|
|
81
88
|
}
|
82
89
|
|
83
90
|
//borrowed from AMD-Utils
|
84
|
-
function decodeQueryString(str) {
|
91
|
+
function decodeQueryString(str, shouldTypecast) {
|
85
92
|
var queryArr = (str || '').replace('?', '').split('&'),
|
86
93
|
n = queryArr.length,
|
87
94
|
obj = {},
|
88
95
|
item, val;
|
89
96
|
while (n--) {
|
90
97
|
item = queryArr[n].split('=');
|
91
|
-
val = typecastValue(item[1]);
|
98
|
+
val = shouldTypecast ? typecastValue(item[1]) : item[1];
|
92
99
|
obj[item[0]] = (typeof val === 'string')? decodeURIComponent(val) : val;
|
93
100
|
}
|
94
101
|
return obj;
|
@@ -106,29 +113,34 @@ define(['signals'], function (signals) {
|
|
106
113
|
this.routed = new signals.Signal();
|
107
114
|
this._routes = [];
|
108
115
|
this._prevRoutes = [];
|
116
|
+
this._piped = [];
|
109
117
|
this.resetState();
|
110
118
|
}
|
111
119
|
|
112
120
|
Crossroads.prototype = {
|
113
121
|
|
114
|
-
resetState : function(){
|
115
|
-
this._prevRoutes.length = 0;
|
116
|
-
this._prevMatchedRequest = null;
|
117
|
-
this._prevBypassedRequest = null;
|
118
|
-
},
|
119
|
-
|
120
122
|
greedy : false,
|
121
123
|
|
122
124
|
greedyEnabled : true,
|
123
125
|
|
126
|
+
ignoreCase : true,
|
127
|
+
|
128
|
+
ignoreState : false,
|
129
|
+
|
130
|
+
shouldTypecast : false,
|
131
|
+
|
124
132
|
normalizeFn : null,
|
125
133
|
|
134
|
+
resetState : function(){
|
135
|
+
this._prevRoutes.length = 0;
|
136
|
+
this._prevMatchedRequest = null;
|
137
|
+
this._prevBypassedRequest = null;
|
138
|
+
},
|
139
|
+
|
126
140
|
create : function () {
|
127
141
|
return new Crossroads();
|
128
142
|
},
|
129
143
|
|
130
|
-
shouldTypecast : false,
|
131
|
-
|
132
144
|
addRoute : function (pattern, callback, priority) {
|
133
145
|
var route = new Route(pattern, callback, priority, this);
|
134
146
|
this._sortedInsert(route);
|
@@ -136,10 +148,7 @@ define(['signals'], function (signals) {
|
|
136
148
|
},
|
137
149
|
|
138
150
|
removeRoute : function (route) {
|
139
|
-
|
140
|
-
if (i !== -1) {
|
141
|
-
this._routes.splice(i, 1);
|
142
|
-
}
|
151
|
+
arrayRemove(this._routes, route);
|
143
152
|
route._destroy();
|
144
153
|
},
|
145
154
|
|
@@ -155,8 +164,10 @@ define(['signals'], function (signals) {
|
|
155
164
|
request = request || '';
|
156
165
|
defaultArgs = defaultArgs || [];
|
157
166
|
|
158
|
-
// should only care about different requests
|
159
|
-
if (
|
167
|
+
// should only care about different requests if ignoreState isn't true
|
168
|
+
if ( !this.ignoreState &&
|
169
|
+
(request === this._prevMatchedRequest ||
|
170
|
+
request === this._prevBypassedRequest) ) {
|
160
171
|
return;
|
161
172
|
}
|
162
173
|
|
@@ -183,6 +194,7 @@ define(['signals'], function (signals) {
|
|
183
194
|
this.bypassed.dispatch.apply(this.bypassed, defaultArgs.concat([request]));
|
184
195
|
}
|
185
196
|
|
197
|
+
this._pipeParse(request, defaultArgs);
|
186
198
|
},
|
187
199
|
|
188
200
|
_notifyPrevRoutes : function(matchedRoutes, request) {
|
@@ -207,6 +219,13 @@ define(['signals'], function (signals) {
|
|
207
219
|
return true;
|
208
220
|
},
|
209
221
|
|
222
|
+
_pipeParse : function(request, defaultArgs) {
|
223
|
+
var i = 0, route;
|
224
|
+
while (route = this._piped[i++]) {
|
225
|
+
route.parse(request, defaultArgs);
|
226
|
+
}
|
227
|
+
},
|
228
|
+
|
210
229
|
getNumRoutes : function () {
|
211
230
|
return this._routes.length;
|
212
231
|
},
|
@@ -239,6 +258,14 @@ define(['signals'], function (signals) {
|
|
239
258
|
return res;
|
240
259
|
},
|
241
260
|
|
261
|
+
pipe : function (otherRouter) {
|
262
|
+
this._piped.push(otherRouter);
|
263
|
+
},
|
264
|
+
|
265
|
+
unpipe : function (otherRouter) {
|
266
|
+
arrayRemove(this._piped, otherRouter);
|
267
|
+
},
|
268
|
+
|
242
269
|
toString : function () {
|
243
270
|
return '[crossroads numRoutes:'+ this.getNumRoutes() +']';
|
244
271
|
}
|
@@ -246,7 +273,7 @@ define(['signals'], function (signals) {
|
|
246
273
|
|
247
274
|
//"static" instance
|
248
275
|
crossroads = new Crossroads();
|
249
|
-
crossroads.VERSION = '0.
|
276
|
+
crossroads.VERSION = '0.11.0';
|
250
277
|
|
251
278
|
crossroads.NORM_AS_ARRAY = function (req, vals) {
|
252
279
|
return [vals.vals_];
|
@@ -270,7 +297,7 @@ define(['signals'], function (signals) {
|
|
270
297
|
this._pattern = pattern;
|
271
298
|
this._paramsIds = isRegexPattern? null : patternLexer.getParamIds(pattern);
|
272
299
|
this._optionalParamsIds = isRegexPattern? null : patternLexer.getOptionalParamsIds(pattern);
|
273
|
-
this._matchRegexp = isRegexPattern? pattern : patternLexer.compilePattern(pattern);
|
300
|
+
this._matchRegexp = isRegexPattern? pattern : patternLexer.compilePattern(pattern, router.ignoreCase);
|
274
301
|
this.matched = new signals.Signal();
|
275
302
|
this.switched = new signals.Signal();
|
276
303
|
if (callback) {
|
@@ -322,7 +349,7 @@ define(['signals'], function (signals) {
|
|
322
349
|
if (isQuery) {
|
323
350
|
val = values[prop +'_']; //use raw string
|
324
351
|
}
|
325
|
-
isValid =
|
352
|
+
isValid = this._isValidArrayRule(validationRule, val);
|
326
353
|
}
|
327
354
|
else if (isFunction(validationRule)) {
|
328
355
|
isValid = validationRule(val, request, values);
|
@@ -331,6 +358,29 @@ define(['signals'], function (signals) {
|
|
331
358
|
return isValid; //fail silently if validationRule is from an unsupported type
|
332
359
|
},
|
333
360
|
|
361
|
+
_isValidArrayRule : function (arr, val) {
|
362
|
+
if (! this._router.ignoreCase) {
|
363
|
+
return arrayIndexOf(arr, val) !== -1;
|
364
|
+
}
|
365
|
+
|
366
|
+
if (typeof val === 'string') {
|
367
|
+
val = val.toLowerCase();
|
368
|
+
}
|
369
|
+
|
370
|
+
var n = arr.length,
|
371
|
+
item,
|
372
|
+
compareVal;
|
373
|
+
|
374
|
+
while (n--) {
|
375
|
+
item = arr[n];
|
376
|
+
compareVal = (typeof item === 'string')? item.toLowerCase() : item;
|
377
|
+
if (compareVal === val) {
|
378
|
+
return true;
|
379
|
+
}
|
380
|
+
}
|
381
|
+
return false;
|
382
|
+
},
|
383
|
+
|
334
384
|
_getParamsObject : function (request) {
|
335
385
|
var shouldTypecast = this._router.shouldTypecast,
|
336
386
|
values = crossroads.patternLexer.getParamValues(request, this._matchRegexp, shouldTypecast),
|
@@ -347,7 +397,7 @@ define(['signals'], function (signals) {
|
|
347
397
|
o[param +'_'] = val;
|
348
398
|
//update vals_ array as well since it will be used
|
349
399
|
//during dispatch
|
350
|
-
val = decodeQueryString(val);
|
400
|
+
val = decodeQueryString(val, shouldTypecast);
|
351
401
|
values[n] = val;
|
352
402
|
}
|
353
403
|
// IE will capture optional groups as empty strings while other
|
@@ -514,7 +564,7 @@ define(['signals'], function (signals) {
|
|
514
564
|
return captureVals(TOKENS.OP.rgx, pattern);
|
515
565
|
}
|
516
566
|
|
517
|
-
function compilePattern(pattern) {
|
567
|
+
function compilePattern(pattern, ignoreCase) {
|
518
568
|
pattern = pattern || '';
|
519
569
|
|
520
570
|
if(pattern){
|
@@ -541,7 +591,7 @@ define(['signals'], function (signals) {
|
|
541
591
|
//single slash is treated as empty and end slash is optional
|
542
592
|
pattern += '\\/?';
|
543
593
|
}
|
544
|
-
return new RegExp('^'+ pattern + '$');
|
594
|
+
return new RegExp('^'+ pattern + '$', ignoreCase? 'i' : '');
|
545
595
|
}
|
546
596
|
|
547
597
|
function replaceTokens(pattern, regexpName, replaceName) {
|
@@ -2,6 +2,6 @@
|
|
2
2
|
* crossroads <http://millermedeiros.github.com/crossroads.js/>
|
3
3
|
* License: MIT
|
4
4
|
* Author: Miller Medeiros
|
5
|
-
* Version: 0.
|
5
|
+
* Version: 0.11.0 (2012/10/31 21:44)
|
6
6
|
*/
|
7
|
-
(function(a){a(["signals"],function(a){function e(a,b){if(a.indexOf)return a.indexOf(b);var c=a.length;while(c--)if(a[c]===b)return c;return-1}function f(a,b){return"[object "+b+"]"===Object.prototype.toString.call(a)}function
|
7
|
+
(function(a){a(["signals"],function(a){function e(a,b){if(a.indexOf)return a.indexOf(b);var c=a.length;while(c--)if(a[c]===b)return c;return-1}function f(a,b){var c=e(a,b);c!==-1&&a.splice(c,1)}function g(a,b){return"[object "+b+"]"===Object.prototype.toString.call(a)}function h(a){return g(a,"RegExp")}function i(a){return g(a,"Array")}function j(a){return typeof a=="function"}function k(a){var b;return a===null||a==="null"?b=null:a==="true"?b=!0:a==="false"?b=!1:a===d||a==="undefined"?b=d:a===""||isNaN(a)?b=a:b=parseFloat(a),b}function l(a){var b=a.length,c=[];while(b--)c[b]=k(a[b]);return c}function m(a,b){var c=(a||"").replace("?","").split("&"),d=c.length,e={},f,g;while(d--)f=c[d].split("="),g=b?k(f[1]):f[1],e[f[0]]=typeof g=="string"?decodeURIComponent(g):g;return e}function n(){this.bypassed=new a.Signal,this.routed=new a.Signal,this._routes=[],this._prevRoutes=[],this._piped=[],this.resetState()}function o(c,d,e,f){var g=h(c),i=b.patternLexer;this._router=f,this._pattern=c,this._paramsIds=g?null:i.getParamIds(c),this._optionalParamsIds=g?null:i.getOptionalParamsIds(c),this._matchRegexp=g?c:i.compilePattern(c,f.ignoreCase),this.matched=new a.Signal,this.switched=new a.Signal,d&&this.matched.add(d),this._priority=e||0}var b,c,d;return c=/t(.+)?/.exec("t")[1]==="",n.prototype={greedy:!1,greedyEnabled:!0,ignoreCase:!0,ignoreState:!1,shouldTypecast:!1,normalizeFn:null,resetState:function(){this._prevRoutes.length=0,this._prevMatchedRequest=null,this._prevBypassedRequest=null},create:function(){return new n},addRoute:function(a,b,c){var d=new o(a,b,c,this);return this._sortedInsert(d),d},removeRoute:function(a){f(this._routes,a),a._destroy()},removeAllRoutes:function(){var a=this.getNumRoutes();while(a--)this._routes[a]._destroy();this._routes.length=0},parse:function(a,b){a=a||"",b=b||[];if(!this.ignoreState&&(a===this._prevMatchedRequest||a===this._prevBypassedRequest))return;var c=this._getMatchedRoutes(a),d=0,e=c.length,f;if(e){this._prevMatchedRequest=a,this._notifyPrevRoutes(c,a),this._prevRoutes=c;while(d<e)f=c[d],f.route.matched.dispatch.apply(f.route.matched,b.concat(f.params)),f.isFirst=!d,this.routed.dispatch.apply(this.routed,b.concat([a,f])),d+=1}else this._prevBypassedRequest=a,this.bypassed.dispatch.apply(this.bypassed,b.concat([a]));this._pipeParse(a,b)},_notifyPrevRoutes:function(a,b){var c=0,d;while(d=this._prevRoutes[c++])d.route.switched&&this._didSwitch(d.route,a)&&d.route.switched.dispatch(b)},_didSwitch:function(a,b){var c,d=0;while(c=b[d++])if(c.route===a)return!1;return!0},_pipeParse:function(a,b){var c=0,d;while(d=this._piped[c++])d.parse(a,b)},getNumRoutes:function(){return this._routes.length},_sortedInsert:function(a){var b=this._routes,c=b.length;do--c;while(b[c]&&a._priority<=b[c]._priority);b.splice(c+1,0,a)},_getMatchedRoutes:function(a){var b=[],c=this._routes,d=c.length,e;while(e=c[--d]){(!b.length||this.greedy||e.greedy)&&e.match(a)&&b.push({route:e,params:e._getParamsArray(a)});if(!this.greedyEnabled&&b.length)break}return b},pipe:function(a){this._piped.push(a)},unpipe:function(a){f(this._piped,a)},toString:function(){return"[crossroads numRoutes:"+this.getNumRoutes()+"]"}},b=new n,b.VERSION="0.11.0",b.NORM_AS_ARRAY=function(a,b){return[b.vals_]},b.NORM_AS_OBJECT=function(a,b){return[b]},o.prototype={greedy:!1,rules:void 0,match:function(a){return a=a||"",this._matchRegexp.test(a)&&this._validateParams(a)},_validateParams:function(a){var b=this.rules,c=this._getParamsObject(a),d;for(d in b)if(d!=="normalize_"&&b.hasOwnProperty(d)&&!this._isValidParam(a,d,c))return!1;return!0},_isValidParam:function(a,b,c){var d=this.rules[b],f=c[b],g=!1,k=b.indexOf("?")===0;return f==null&&this._optionalParamsIds&&e(this._optionalParamsIds,b)!==-1?g=!0:h(d)?(k&&(f=c[b+"_"]),g=d.test(f)):i(d)?(k&&(f=c[b+"_"]),g=this._isValidArrayRule(d,f)):j(d)&&(g=d(f,a,c)),g},_isValidArrayRule:function(a,b){if(!this._router.ignoreCase)return e(a,b)!==-1;typeof b=="string"&&(b=b.toLowerCase());var c=a.length,d,f;while(c--){d=a[c],f=typeof d=="string"?d.toLowerCase():d;if(f===b)return!0}return!1},_getParamsObject:function(a){var d=this._router.shouldTypecast,f=b.patternLexer.getParamValues(a,this._matchRegexp,d),g={},h=f.length,i,j;while(h--)j=f[h],this._paramsIds&&(i=this._paramsIds[h],i.indexOf("?")===0&&j&&(g[i+"_"]=j,j=m(j,d),f[h]=j),c&&j===""&&e(this._optionalParamsIds,i)!==-1&&(j=void 0,f[h]=j),g[i]=j),g[h]=j;return g.request_=d?k(a):a,g.vals_=f,g},_getParamsArray:function(a){var b=this.rules?this.rules.normalize_:null,c;return b=b||this._router.normalizeFn,b&&j(b)?c=b(a,this._getParamsObject(a)):c=this._getParamsObject(a).vals_,c},interpolate:function(a){var c=b.patternLexer.interpolate(this._pattern,a);if(!this._validateParams(c))throw new Error("Generated string doesn't validate against `Route.rules`.");return c},dispose:function(){this._router.removeRoute(this)},_destroy:function(){this.matched.dispose(),this.switched.dispose(),this.matched=this.switched=this._pattern=this._matchRegexp=null},toString:function(){return'[Route pattern:"'+this._pattern+'", numListeners:'+this.matched.getNumListeners()+"]"}},b.patternLexer=function(){function j(){var a,b;for(a in e)e.hasOwnProperty(a)&&(b=e[a],b.id="__CR_"+a+"__",b.save="save"in b?b.save.replace("{{id}}",b.id):b.id,b.rRestore=new RegExp(b.id,"g"))}function k(a,b){var c=[],d;a.lastIndex=0;while(d=a.exec(b))c.push(d[1]);return c}function m(a){return k(d,a)}function n(a){return k(e.OP.rgx,a)}function o(d,e){return d=d||"",d&&(i===f?d=d.replace(b,""):i===h&&(d=d.replace(c,"")),d=p(d,"rgx","save"),d=d.replace(a,"\\$&"),d=p(d,"rRestore","res"),i===f&&(d="\\/?"+d)),i!==g&&(d+="\\/?"),new RegExp("^"+d+"$",e?"i":"")}function p(a,b,c){var d,f;for(f in e)e.hasOwnProperty(f)&&(d=e[f],a=a.replace(d[b],d[c]));return a}function q(a,b,c){var d=b.exec(a);return d&&(d.shift(),c&&(d=l(d))),d}function r(a,b){if(typeof a!="string")throw new Error("Route pattern should be a string.");var c=function(a,c){var d;if(c in b){d=String(b[c]);if(a.indexOf("*")===-1&&d.indexOf("/")!==-1)throw new Error('Invalid value "'+d+'" for segment "'+a+'".')}else{if(a.indexOf("{")!==-1)throw new Error("The segment "+a+" is required.");d=""}return d};return e.OS.trail||(e.OS.trail=new RegExp("(?:"+e.OS.id+")+$")),a.replace(e.OS.rgx,e.OS.save).replace(d,c).replace(e.OS.trail,"").replace(e.OS.rRestore,"/")}var a=/[\\.+*?\^$\[\](){}\/'#]/g,b=/^\/|\/$/g,c=/\/$/g,d=/(?:\{|:)([^}:]+)(?:\}|:)/g,e={OS:{rgx:/([:}]|\w(?=\/))\/?(:|(?:\{\?))/g,save:"$1{{id}}$2",res:"\\/?"},RS:{rgx:/([:}])\/?(\{)/g,save:"$1{{id}}$2",res:"\\/"},RQ:{rgx:/\{\?([^}]+)\}/g,res:"\\?([^#]+)"},OQ:{rgx:/:\?([^:]+):/g,res:"(?:\\?([^#]*))?"},OR:{rgx:/:([^:]+)\*:/g,res:"(.*)?"},RR:{rgx:/\{([^}]+)\*\}/g,res:"(.+)"},RP:{rgx:/\{([^}]+)\}/g,res:"([^\\/?]+)"},OP:{rgx:/:([^:]+):/g,res:"([^\\/?]+)?/?"}},f=1,g=2,h=3,i=f;return j(),{strict:function(){i=g},loose:function(){i=f},legacy:function(){i=h},getParamIds:m,getOptionalParamsIds:n,getParamValues:q,compilePattern:o,interpolate:r}}(),b})})(typeof define=="function"&&define.amd?define:function(a,b){typeof module!="undefined"&&module.exports?module.exports=b(require(a[0])):window.crossroads=b(window[a[0]])})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crossroadsjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|