Skip to content

Commit

Permalink
chore(all): prepare release 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Jan 12, 2015
1 parent b7f403b commit 64ba4bd
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 74 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-route-recognizer",
"version": "0.2.0",
"version": "0.2.1",
"description": "A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.",
"keywords": [
"aurelia",
Expand Down
3 changes: 2 additions & 1 deletion dist/amd/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ define(["exports"], function (exports) {

function addRoute(routeArray, path, handler) {
var len = 0;
for (var i = 0, l = routeArray.length; i < l; i++) {
for (var i = 0,
l = routeArray.length; i < l; i++) {
len += routeArray[i].path.length;
}

Expand Down
77 changes: 54 additions & 23 deletions dist/amd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ define(["exports", "./dsl"], function (exports, _dsl) {
eachChar: function (callback) {
var string = this.string, ch;

for (var i = 0, l = string.length; i < l; i++) {
for (var i = 0,
l = string.length; i < l; i++) {
ch = string.charAt(i);
callback({ validChars: ch });
}
Expand Down Expand Up @@ -84,9 +85,11 @@ define(["exports", "./dsl"], function (exports, _dsl) {
route = route.substr(1);
}

var segments = route.split("/"), results = [];
var segments = route.split("/"),
results = [];

for (var i = 0, l = segments.length; i < l; i++) {
for (var i = 0,
l = segments.length; i < l; i++) {
var segment = segments[i], match;

if (match = segment.match(/^:([^\/]+)$/)) {
Expand Down Expand Up @@ -117,7 +120,8 @@ define(["exports", "./dsl"], function (exports, _dsl) {
get: function (charSpec) {
var nextStates = this.nextStates;

for (var i = 0, l = nextStates.length; i < l; i++) {
for (var i = 0,
l = nextStates.length; i < l; i++) {
var child = nextStates[i];

var isEqual = child.charSpec.validChars === charSpec.validChars;
Expand Down Expand Up @@ -151,7 +155,8 @@ define(["exports", "./dsl"], function (exports, _dsl) {

var returned = [];

for (var i = 0, l = nextStates.length; i < l; i++) {
for (var i = 0,
l = nextStates.length; i < l; i++) {
child = nextStates[i];

charSpec = child.charSpec;
Expand Down Expand Up @@ -201,7 +206,8 @@ define(["exports", "./dsl"], function (exports, _dsl) {
function recognizeChar(states, ch) {
var nextStates = [];

for (var i = 0, l = states.length; i < l; i++) {
for (var i = 0,
l = states.length; i < l; i++) {
var state = states[i];

nextStates = nextStates.concat(state.match(ch));
Expand All @@ -228,14 +234,20 @@ define(["exports", "./dsl"], function (exports, _dsl) {
});

function findHandler(state, path, queryParams) {
var handlers = state.handlers, regex = state.regex;
var captures = path.match(regex), currentCapture = 1;
var handlers = state.handlers,
regex = state.regex;
var captures = path.match(regex),
currentCapture = 1;
var result = new RecognizeResults(queryParams);

for (var i = 0, l = handlers.length; i < l; i++) {
var handler = handlers[i], names = handler.names, params = {};
for (var i = 0,
l = handlers.length; i < l; i++) {
var handler = handlers[i],
names = handler.names,
params = {};

for (var j = 0, m = names.length; j < m; j++) {
for (var j = 0,
m = names.length; j < m; j++) {
params[names[j]] = captures[currentCapture++];
}

Expand Down Expand Up @@ -263,18 +275,26 @@ define(["exports", "./dsl"], function (exports, _dsl) {

RouteRecognizer.prototype = {
add: function (routes, options) {
var currentState = this.rootState, regex = "^", types = { statics: 0, dynamics: 0, stars: 0 }, handlers = [], allSegments = [], name;
var currentState = this.rootState,
regex = "^",
types = { statics: 0, dynamics: 0, stars: 0 },
handlers = [],
allSegments = [],
name;

var isEmpty = true;

for (var i = 0, l = routes.length; i < l; i++) {
var route = routes[i], names = [];
for (var i = 0,
l = routes.length; i < l; i++) {
var route = routes[i],
names = [];

var segments = parse(route.path, names, types);

allSegments = allSegments.concat(segments);

for (var j = 0, m = segments.length; j < m; j++) {
for (var j = 0,
m = segments.length; j < m; j++) {
var segment = segments[j];

if (segment instanceof EpsilonSegment) {
Expand Down Expand Up @@ -312,12 +332,14 @@ define(["exports", "./dsl"], function (exports, _dsl) {
},

handlersFor: function (name) {
var route = this.names[name], result = [];
var route = this.names[name],
result = [];
if (!route) {
throw new Error("There is no route named " + name);
}

for (var i = 0, l = route.handlers.length; i < l; i++) {
for (var i = 0,
l = route.handlers.length; i < l; i++) {
result.push(route.handlers[i]);
}

Expand All @@ -329,14 +351,16 @@ define(["exports", "./dsl"], function (exports, _dsl) {
},

generate: function (name, params) {
var route = this.names[name], output = "";
var route = this.names[name],
output = "";
if (!route) {
throw new Error("There is no route named " + name);
}

var segments = route.segments;

for (var i = 0, l = segments.length; i < l; i++) {
for (var i = 0,
l = segments.length; i < l; i++) {
var segment = segments[i];

if (segment instanceof EpsilonSegment) {
Expand Down Expand Up @@ -367,15 +391,17 @@ define(["exports", "./dsl"], function (exports, _dsl) {
}
}
keys.sort();
for (var i = 0, len = keys.length; i < len; i++) {
for (var i = 0,
len = keys.length; i < len; i++) {
key = keys[i];
var value = params[key];
if (value === null) {
continue;
}
var pair = encodeURIComponent(key);
if (isArray(value)) {
for (var j = 0, l = value.length; j < l; j++) {
for (var j = 0,
l = value.length; j < l; j++) {
var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]);
pairs.push(arrayPair);
}
Expand All @@ -393,9 +419,14 @@ define(["exports", "./dsl"], function (exports, _dsl) {
},

parseQueryString: function (queryString) {
var pairs = queryString.split("&"), queryParams = {};
var pairs = queryString.split("&"),
queryParams = {};
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("="), key = decodeURIComponent(pair[0]), keyLength = key.length, isArray = false, value;
var pair = pairs[i].split("="),
key = decodeURIComponent(pair[0]),
keyLength = key.length,
isArray = false,
value;
if (pair.length === 1) {
value = "true";
} else {
Expand Down
3 changes: 2 additions & 1 deletion dist/commonjs/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function generateMatch(startingPath, matcher, delegate) {

function addRoute(routeArray, path, handler) {
var len = 0;
for (var i = 0, l = routeArray.length; i < l; i++) {
for (var i = 0,
l = routeArray.length; i < l; i++) {
len += routeArray[i].path.length;
}

Expand Down
77 changes: 54 additions & 23 deletions dist/commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ StaticSegment.prototype = {
eachChar: function (callback) {
var string = this.string, ch;

for (var i = 0, l = string.length; i < l; i++) {
for (var i = 0,
l = string.length; i < l; i++) {
ch = string.charAt(i);
callback({ validChars: ch });
}
Expand Down Expand Up @@ -83,9 +84,11 @@ function parse(route, names, types) {
route = route.substr(1);
}

var segments = route.split("/"), results = [];
var segments = route.split("/"),
results = [];

for (var i = 0, l = segments.length; i < l; i++) {
for (var i = 0,
l = segments.length; i < l; i++) {
var segment = segments[i], match;

if (match = segment.match(/^:([^\/]+)$/)) {
Expand Down Expand Up @@ -116,7 +119,8 @@ State.prototype = {
get: function (charSpec) {
var nextStates = this.nextStates;

for (var i = 0, l = nextStates.length; i < l; i++) {
for (var i = 0,
l = nextStates.length; i < l; i++) {
var child = nextStates[i];

var isEqual = child.charSpec.validChars === charSpec.validChars;
Expand Down Expand Up @@ -150,7 +154,8 @@ State.prototype = {

var returned = [];

for (var i = 0, l = nextStates.length; i < l; i++) {
for (var i = 0,
l = nextStates.length; i < l; i++) {
child = nextStates[i];

charSpec = child.charSpec;
Expand Down Expand Up @@ -200,7 +205,8 @@ function sortSolutions(states) {
function recognizeChar(states, ch) {
var nextStates = [];

for (var i = 0, l = states.length; i < l; i++) {
for (var i = 0,
l = states.length; i < l; i++) {
var state = states[i];

nextStates = nextStates.concat(state.match(ch));
Expand All @@ -227,14 +233,20 @@ RecognizeResults.prototype = oCreate({
});

function findHandler(state, path, queryParams) {
var handlers = state.handlers, regex = state.regex;
var captures = path.match(regex), currentCapture = 1;
var handlers = state.handlers,
regex = state.regex;
var captures = path.match(regex),
currentCapture = 1;
var result = new RecognizeResults(queryParams);

for (var i = 0, l = handlers.length; i < l; i++) {
var handler = handlers[i], names = handler.names, params = {};
for (var i = 0,
l = handlers.length; i < l; i++) {
var handler = handlers[i],
names = handler.names,
params = {};

for (var j = 0, m = names.length; j < m; j++) {
for (var j = 0,
m = names.length; j < m; j++) {
params[names[j]] = captures[currentCapture++];
}

Expand Down Expand Up @@ -262,18 +274,26 @@ var RouteRecognizer = exports.RouteRecognizer = function () {

RouteRecognizer.prototype = {
add: function (routes, options) {
var currentState = this.rootState, regex = "^", types = { statics: 0, dynamics: 0, stars: 0 }, handlers = [], allSegments = [], name;
var currentState = this.rootState,
regex = "^",
types = { statics: 0, dynamics: 0, stars: 0 },
handlers = [],
allSegments = [],
name;

var isEmpty = true;

for (var i = 0, l = routes.length; i < l; i++) {
var route = routes[i], names = [];
for (var i = 0,
l = routes.length; i < l; i++) {
var route = routes[i],
names = [];

var segments = parse(route.path, names, types);

allSegments = allSegments.concat(segments);

for (var j = 0, m = segments.length; j < m; j++) {
for (var j = 0,
m = segments.length; j < m; j++) {
var segment = segments[j];

if (segment instanceof EpsilonSegment) {
Expand Down Expand Up @@ -311,12 +331,14 @@ RouteRecognizer.prototype = {
},

handlersFor: function (name) {
var route = this.names[name], result = [];
var route = this.names[name],
result = [];
if (!route) {
throw new Error("There is no route named " + name);
}

for (var i = 0, l = route.handlers.length; i < l; i++) {
for (var i = 0,
l = route.handlers.length; i < l; i++) {
result.push(route.handlers[i]);
}

Expand All @@ -328,14 +350,16 @@ RouteRecognizer.prototype = {
},

generate: function (name, params) {
var route = this.names[name], output = "";
var route = this.names[name],
output = "";
if (!route) {
throw new Error("There is no route named " + name);
}

var segments = route.segments;

for (var i = 0, l = segments.length; i < l; i++) {
for (var i = 0,
l = segments.length; i < l; i++) {
var segment = segments[i];

if (segment instanceof EpsilonSegment) {
Expand Down Expand Up @@ -366,15 +390,17 @@ RouteRecognizer.prototype = {
}
}
keys.sort();
for (var i = 0, len = keys.length; i < len; i++) {
for (var i = 0,
len = keys.length; i < len; i++) {
key = keys[i];
var value = params[key];
if (value === null) {
continue;
}
var pair = encodeURIComponent(key);
if (isArray(value)) {
for (var j = 0, l = value.length; j < l; j++) {
for (var j = 0,
l = value.length; j < l; j++) {
var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]);
pairs.push(arrayPair);
}
Expand All @@ -392,9 +418,14 @@ RouteRecognizer.prototype = {
},

parseQueryString: function (queryString) {
var pairs = queryString.split("&"), queryParams = {};
var pairs = queryString.split("&"),
queryParams = {};
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("="), key = decodeURIComponent(pair[0]), keyLength = key.length, isArray = false, value;
var pair = pairs[i].split("="),
key = decodeURIComponent(pair[0]),
keyLength = key.length,
isArray = false,
value;
if (pair.length === 1) {
value = "true";
} else {
Expand Down
Loading

0 comments on commit 64ba4bd

Please sign in to comment.