This commit is contained in:
thosakwe 2016-10-22 20:52:28 -04:00
parent 7a699456d2
commit 5241e66eff
7 changed files with 65 additions and 48 deletions

View file

@ -170,12 +170,16 @@ class Route {
Iterable handlers: const [],
method: "GET",
String name: null}) {
Route result;
if (path is RegExp) {
result = new Route(path, debug: debug);
} else {
final segments = path
.toString()
.split('/')
.where((str) => str.isNotEmpty)
.toList(growable: false);
Route result;
if (segments.isEmpty) {
return new Route('/',
@ -203,6 +207,7 @@ class Route {
}
}
}
}
result._children.addAll(children);
result._handlers.addAll(handlers);
@ -354,6 +359,8 @@ class Route {
///
/// Can be used to navigate a route hierarchy like a file system.
Route resolve(String path, {bool filter(Route route), String fullPath}) {
_printDebug(
'Path to resolve: "/${path.replaceAll(_straySlashes, '')}", our matcher: ${matcher.pattern}');
bool _filter(route) {
if (filter == null) {
_printDebug('No filter provided, returning true for $route');
@ -484,15 +491,15 @@ class Route {
'Trying to match full $_fullPath for ${route.path} on ${this.path}');
if ((route.match(_fullPath) != null ||
route._resolver.firstMatch(_fullPath) != null) &&
_filter(route))
_filter(route)) {
_printDebug('Matched full path!');
return route.resolve('');
else if ((route.match(_fullPath) != null ||
route._resolver.firstMatch(_fullPath) != null) &&
_filter(route))
return route.resolve('');
else if ((route.match('/$_fullPath') != null ||
} else if ((route.match('/$_fullPath') != null ||
route._resolver.firstMatch('/$_fullPath') != null) &&
_filter(route)) return route.resolve('');
_filter(route)) {
_printDebug('Matched full path (with a leading slash!)');
return route.resolve('');
}
}
// Lastly, check to see if we have an index route to resolve with

View file

@ -55,7 +55,8 @@ class Router extends Extensible {
return new Route('/', debug: debug, handlers: handlers, method: method)
..debug = debug;
} else {
result = resolve(segments[0], (route) => route.method == method || route.method == '*');
result = resolve(segments[0],
(route) => route.method == method || route.method == '*');
if (result != null) {
if (segments.length > 1) {
@ -65,7 +66,9 @@ class Router extends Extensible {
Route existing;
do {
existing = result.resolve(segments[0], filter: (route) => route.method == method || route.method == '*');
existing = result.resolve(segments[0],
filter: (route) =>
route.method == method || route.method == '*');
if (existing != null) {
result = existing;
@ -106,12 +109,12 @@ class Router extends Extensible {
var tabs = 0;
final buf = new StringBuffer();
void dumpRoute(Route route, {String replace: null}) {
void dumpRoute(Route route, {Pattern replace: null}) {
for (var i = 0; i < tabs; i++) buf.write(tab);
if (route == root)
buf.write('(root) ${route.method} ');
else
buf.write('(root)');
else {
buf.write('- ${route.method} ');
final p =
@ -126,9 +129,11 @@ class Router extends Extensible {
buf.writeln(' => ${route.handlers.length} handler(s)');
else
buf.writeln();
}
tabs++;
route.children.forEach((r) => dumpRoute(r, replace: route.path));
route.children
.forEach((r) => dumpRoute(r, replace: new RegExp("^${route.path}")));
tabs--;
}

1
test/server/packages Symbolic link
View file

@ -0,0 +1 @@
../../packages

1
web/hash/packages Symbolic link
View file

@ -0,0 +1 @@
../../packages

1
web/packages Symbolic link
View file

@ -0,0 +1 @@
../packages

1
web/push_state/packages Symbolic link
View file

@ -0,0 +1 @@
../../packages

1
web/shared/packages Symbolic link
View file

@ -0,0 +1 @@
../../packages