Permalink
Browse files

Build Router.

  • Loading branch information...
1 parent bd2cb9b commit 8225ffb96b9d13d1ca252f6530e1ff824bb4207f @ericf ericf committed Nov 9, 2012
Showing with 360 additions and 327 deletions.
  1. +319 −306 build/router/router-coverage.js
  2. +20 −10 build/router/router-debug.js
  3. +1 −1 build/router/router-min.js
  4. +20 −10 build/router/router.js

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -11,7 +11,6 @@ Provides URL-based routing using HTML5 `pushState()` or the location hash.
var HistoryHash = Y.HistoryHash,
QS = Y.QueryString,
YArray = Y.Array,
- YLang = Y.Lang,
win = Y.config.win,
@@ -199,7 +198,9 @@ Y.Router = Y.extend(Router, Y.Base, {
instances.splice(instanceIndex, 1);
}
- this._historyEvents && this._historyEvents.detach();
+ if (this._historyEvents) {
+ this._historyEvents.detach();
+ }
},
// -- Public Methods -------------------------------------------------------
@@ -621,6 +622,7 @@ Y.Router = Y.extend(Router, Y.Base, {
**/
_dispatch: function (path, url, src) {
var self = this,
+ decode = self._decode,
routes = self.match(path),
callbacks = [],
matches, req, res;
@@ -659,9 +661,13 @@ Y.Router = Y.extend(Router, Y.Base, {
callback.call(self, req, res, req.next);
} else if ((route = routes.shift())) {
- // Make a copy of this route's `callbacks` and find its matches.
+ // Make a copy of this route's `callbacks` so the original array
+ // is preserved.
callbacks = route.callbacks.concat();
- matches = route.regex.exec(path);
+
+ // Decode each of the path matches so that the any URL-encoded
+ // path segments are decoded in the `req.params` object.
+ matches = YArray.map(route.regex.exec(path) || [], decode);
// Use named keys for parameter names if the route path contains
// named keys. Otherwise, use numerical match indices.
@@ -671,7 +677,7 @@ Y.Router = Y.extend(Router, Y.Base, {
req.params = matches.concat();
}
- // Allow access tot he num of remaining routes for this request.
+ // Allow access to the num of remaining routes for this request.
req.pendingRoutes = routes.length;
// Execute this route's `callbacks`.
@@ -1152,7 +1158,9 @@ Y.Router = Y.extend(Router, Y.Base, {
}
// Joins the `url` with the `root`.
- urlIsString && (url = this._joinURL(url));
+ if (urlIsString) {
+ url = this._joinURL(url);
+ }
// Force _ready to true to ensure that the history change is handled
// even if _save is called before the `ready` event fires.
@@ -1236,11 +1244,13 @@ Y.Router = Y.extend(Router, Y.Base, {
hash = hash.replace(hashPrefix, '');
}
- hash && (hashPath = this._getHashPath(hash));
-
// If the hash looks like a URL path, assume it is, and upgrade it!
- if (hashPath) {
- return this._resolveURL(hashPath);
+ if (hash) {
+ hashPath = this._getHashPath(hash);
+
+ if (hashPath) {
+ return this._resolveURL(hashPath);
+ }
}
return url;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -11,7 +11,6 @@ Provides URL-based routing using HTML5 `pushState()` or the location hash.
var HistoryHash = Y.HistoryHash,
QS = Y.QueryString,
YArray = Y.Array,
- YLang = Y.Lang,
win = Y.config.win,
@@ -199,7 +198,9 @@ Y.Router = Y.extend(Router, Y.Base, {
instances.splice(instanceIndex, 1);
}
- this._historyEvents && this._historyEvents.detach();
+ if (this._historyEvents) {
+ this._historyEvents.detach();
+ }
},
// -- Public Methods -------------------------------------------------------
@@ -618,6 +619,7 @@ Y.Router = Y.extend(Router, Y.Base, {
**/
_dispatch: function (path, url, src) {
var self = this,
+ decode = self._decode,
routes = self.match(path),
callbacks = [],
matches, req, res;
@@ -656,9 +658,13 @@ Y.Router = Y.extend(Router, Y.Base, {
callback.call(self, req, res, req.next);
} else if ((route = routes.shift())) {
- // Make a copy of this route's `callbacks` and find its matches.
+ // Make a copy of this route's `callbacks` so the original array
+ // is preserved.
callbacks = route.callbacks.concat();
- matches = route.regex.exec(path);
+
+ // Decode each of the path matches so that the any URL-encoded
+ // path segments are decoded in the `req.params` object.
+ matches = YArray.map(route.regex.exec(path) || [], decode);
// Use named keys for parameter names if the route path contains
// named keys. Otherwise, use numerical match indices.
@@ -668,7 +674,7 @@ Y.Router = Y.extend(Router, Y.Base, {
req.params = matches.concat();
}
- // Allow access tot he num of remaining routes for this request.
+ // Allow access to the num of remaining routes for this request.
req.pendingRoutes = routes.length;
// Execute this route's `callbacks`.
@@ -1149,7 +1155,9 @@ Y.Router = Y.extend(Router, Y.Base, {
}
// Joins the `url` with the `root`.
- urlIsString && (url = this._joinURL(url));
+ if (urlIsString) {
+ url = this._joinURL(url);
+ }
// Force _ready to true to ensure that the history change is handled
// even if _save is called before the `ready` event fires.
@@ -1233,11 +1241,13 @@ Y.Router = Y.extend(Router, Y.Base, {
hash = hash.replace(hashPrefix, '');
}
- hash && (hashPath = this._getHashPath(hash));
-
// If the hash looks like a URL path, assume it is, and upgrade it!
- if (hashPath) {
- return this._resolveURL(hashPath);
+ if (hash) {
+ hashPath = this._getHashPath(hash);
+
+ if (hashPath) {
+ return this._resolveURL(hashPath);
+ }
}
return url;

0 comments on commit 8225ffb

Please sign in to comment.