crossroadsjs-rails 1.2.1 → 1.3.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.9.1) for use with Rails 3
3
+ Provides Crossroads.js (0.10.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
  module Crossroadsjs
2
2
  module Rails
3
- VERSION = "1.2.1"
4
- CROSSROADSJS_VERSION = "0.9.1";
3
+ VERSION = "1.3.0"
4
+ CROSSROADSJS_VERSION = "0.10.0";
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Crossroadsjs::Rails do
4
- it { Crossroadsjs::Rails::VERSION.should == "1.2.1" }
5
- it { Crossroadsjs::Rails::CROSSROADSJS_VERSION.should == "0.9.1" }
4
+ it { Crossroadsjs::Rails::VERSION.should == "1.3.0" }
5
+ it { Crossroadsjs::Rails::CROSSROADSJS_VERSION.should == "0.10.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.9.1 (2012/7/29 15:56)
5
+ * Version: 0.10.0 (2012/08/12 03:41)
6
6
  */
7
7
 
8
8
  (function (define) {
@@ -102,14 +102,21 @@ define(['signals'], function (signals) {
102
102
  * @constructor
103
103
  */
104
104
  function Crossroads() {
105
- this._routes = [];
106
- this._prevRoutes = [];
107
105
  this.bypassed = new signals.Signal();
108
106
  this.routed = new signals.Signal();
107
+ this._routes = [];
108
+ this._prevRoutes = [];
109
+ this.resetState();
109
110
  }
110
111
 
111
112
  Crossroads.prototype = {
112
113
 
114
+ resetState : function(){
115
+ this._prevRoutes.length = 0;
116
+ this._prevMatchedRequest = null;
117
+ this._prevBypassedRequest = null;
118
+ },
119
+
113
120
  greedy : false,
114
121
 
115
122
  greedyEnabled : true,
@@ -148,15 +155,22 @@ define(['signals'], function (signals) {
148
155
  request = request || '';
149
156
  defaultArgs = defaultArgs || [];
150
157
 
158
+ // should only care about different requests
159
+ if (request === this._prevMatchedRequest || request === this._prevBypassedRequest) {
160
+ return;
161
+ }
162
+
151
163
  var routes = this._getMatchedRoutes(request),
152
164
  i = 0,
153
165
  n = routes.length,
154
166
  cur;
155
167
 
156
168
  if (n) {
169
+ this._prevMatchedRequest = request;
170
+
157
171
  this._notifyPrevRoutes(routes, request);
158
172
  this._prevRoutes = routes;
159
- //shold be incremental loop, execute routes in order
173
+ //should be incremental loop, execute routes in order
160
174
  while (i < n) {
161
175
  cur = routes[i];
162
176
  cur.route.matched.dispatch.apply(cur.route.matched, defaultArgs.concat(cur.params));
@@ -165,8 +179,10 @@ define(['signals'], function (signals) {
165
179
  i += 1;
166
180
  }
167
181
  } else {
182
+ this._prevBypassedRequest = request;
168
183
  this.bypassed.dispatch.apply(this.bypassed, defaultArgs.concat([request]));
169
184
  }
185
+
170
186
  },
171
187
 
172
188
  _notifyPrevRoutes : function(matchedRoutes, request) {
@@ -230,7 +246,7 @@ define(['signals'], function (signals) {
230
246
 
231
247
  //"static" instance
232
248
  crossroads = new Crossroads();
233
- crossroads.VERSION = '0.9.1';
249
+ crossroads.VERSION = '0.10.0';
234
250
 
235
251
  crossroads.NORM_AS_ARRAY = function (req, vals) {
236
252
  return [vals.vals_];
@@ -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.9.1 (2012/7/29 15:56)
5
+ * Version: 0.10.0 (2012/08/12 03:41)
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 g(a){return f(a,"RegExp")}function h(a){return f(a,"Array")}function i(a){return typeof a=="function"}function j(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 k(a){var b=a.length,c=[];while(b--)c[b]=j(a[b]);return c}function l(a){var b=(a||"").replace("?","").split("&"),c=b.length,d={},e,f;while(c--)e=b[c].split("="),f=j(e[1]),d[e[0]]=typeof f=="string"?decodeURIComponent(f):f;return d}function m(){this._routes=[],this._prevRoutes=[],this.bypassed=new a.Signal,this.routed=new a.Signal}function n(c,d,e,f){var h=g(c),i=b.patternLexer;this._router=f,this._pattern=c,this._paramsIds=h?null:i.getParamIds(c),this._optionalParamsIds=h?null:i.getOptionalParamsIds(c),this._matchRegexp=h?c:i.compilePattern(c),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]==="",m.prototype={greedy:!1,greedyEnabled:!0,normalizeFn:null,create:function(){return new m},shouldTypecast:!1,addRoute:function(a,b,c){var d=new n(a,b,c,this);return this._sortedInsert(d),d},removeRoute:function(a){var b=e(this._routes,a);b!==-1&&this._routes.splice(b,1),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||[];var c=this._getMatchedRoutes(a),d=0,e=c.length,f;if(e){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.bypassed.dispatch.apply(this.bypassed,b.concat([a]))},_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},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},toString:function(){return"[crossroads numRoutes:"+this.getNumRoutes()+"]"}},b=new m,b.VERSION="0.9.1",b.NORM_AS_ARRAY=function(a,b){return[b.vals_]},b.NORM_AS_OBJECT=function(a,b){return[b]},n.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],j=!1,k=b.indexOf("?")===0;return f==null&&this._optionalParamsIds&&e(this._optionalParamsIds,b)!==-1?j=!0:g(d)?(k&&(f=c[b+"_"]),j=d.test(f)):h(d)?(k&&(f=c[b+"_"]),j=e(d,f)!==-1):i(d)&&(j=d(f,a,c)),j},_getParamsObject:function(a){var d=this._router.shouldTypecast,f=b.patternLexer.getParamValues(a,this._matchRegexp,d),g={},h=f.length,i,k;while(h--)k=f[h],this._paramsIds&&(i=this._paramsIds[h],i.indexOf("?")===0&&k&&(g[i+"_"]=k,k=l(k),f[h]=k),c&&k===""&&e(this._optionalParamsIds,i)!==-1&&(k=void 0,f[h]=k),g[i]=k),g[h]=k;return g.request_=d?j(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&&i(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 l(a,b){var c=[],d;a.lastIndex=0;while(d=a.exec(b))c.push(d[1]);return c}function m(a){return l(d,a)}function n(a){return l(e.OP.rgx,a)}function o(d){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+"$")}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=k(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]])})
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 g(a){return f(a,"RegExp")}function h(a){return f(a,"Array")}function i(a){return typeof a=="function"}function j(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 k(a){var b=a.length,c=[];while(b--)c[b]=j(a[b]);return c}function l(a){var b=(a||"").replace("?","").split("&"),c=b.length,d={},e,f;while(c--)e=b[c].split("="),f=j(e[1]),d[e[0]]=typeof f=="string"?decodeURIComponent(f):f;return d}function m(){this.bypassed=new a.Signal,this.routed=new a.Signal,this._routes=[],this._prevRoutes=[],this.resetState()}function n(c,d,e,f){var h=g(c),i=b.patternLexer;this._router=f,this._pattern=c,this._paramsIds=h?null:i.getParamIds(c),this._optionalParamsIds=h?null:i.getOptionalParamsIds(c),this._matchRegexp=h?c:i.compilePattern(c),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]==="",m.prototype={resetState:function(){this._prevRoutes.length=0,this._prevMatchedRequest=null,this._prevBypassedRequest=null},greedy:!1,greedyEnabled:!0,normalizeFn:null,create:function(){return new m},shouldTypecast:!1,addRoute:function(a,b,c){var d=new n(a,b,c,this);return this._sortedInsert(d),d},removeRoute:function(a){var b=e(this._routes,a);b!==-1&&this._routes.splice(b,1),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(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]))},_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},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},toString:function(){return"[crossroads numRoutes:"+this.getNumRoutes()+"]"}},b=new m,b.VERSION="0.10.0",b.NORM_AS_ARRAY=function(a,b){return[b.vals_]},b.NORM_AS_OBJECT=function(a,b){return[b]},n.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],j=!1,k=b.indexOf("?")===0;return f==null&&this._optionalParamsIds&&e(this._optionalParamsIds,b)!==-1?j=!0:g(d)?(k&&(f=c[b+"_"]),j=d.test(f)):h(d)?(k&&(f=c[b+"_"]),j=e(d,f)!==-1):i(d)&&(j=d(f,a,c)),j},_getParamsObject:function(a){var d=this._router.shouldTypecast,f=b.patternLexer.getParamValues(a,this._matchRegexp,d),g={},h=f.length,i,k;while(h--)k=f[h],this._paramsIds&&(i=this._paramsIds[h],i.indexOf("?")===0&&k&&(g[i+"_"]=k,k=l(k),f[h]=k),c&&k===""&&e(this._optionalParamsIds,i)!==-1&&(k=void 0,f[h]=k),g[i]=k),g[h]=k;return g.request_=d?j(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&&i(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 l(a,b){var c=[],d;a.lastIndex=0;while(d=a.exec(b))c.push(d[1]);return c}function m(a){return l(d,a)}function n(a){return l(e.OP.rgx,a)}function o(d){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+"$")}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=k(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.2.1
4
+ version: 1.3.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-07-30 00:00:00.000000000 Z
12
+ date: 2012-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties