This commit is contained in:
Tobe O 2019-02-03 00:52:48 -05:00
parent 639d43f42e
commit 0e3e7ee9bb
4 changed files with 21 additions and 19 deletions

View file

@ -1,3 +1,6 @@
# 3.0.3
* Support trailing text after parameters with custom Regexes.
# 3.0.2
* Support leading and trailing text for both `:parameters` and `*`

View file

@ -9,12 +9,11 @@ main() {
router.get('/wild*', () {});
// TODO: Enable trailing after custom RegExp
// router.get('/ordinal/int:n([0-9]+)st', () {});
router.get('/ordinal/int:n([0-9]+)st', () {});
print(router.resolveAbsolute('/whois/~thosakwe').first.allParams);
print(router.resolveAbsolute('/wild_thornberrys').first.route.path);
// print(router.resolveAbsolute('/ordinal/1st').first.allParams);
print(router.resolveAbsolute('/ordinal/1st').first.allParams);
router.get('/users', () {});

View file

@ -7,13 +7,11 @@ class RouteGrammar {
match<String>(new RegExp(notSlashRgx)).value((r) => r.span.text);
static final Parser<Match> regExp =
// TODO: Enable trailing here
// match<Match>(new RegExp(r'\(([^)]+)\)([^/]+)?'))
match<Match>(new RegExp(r'\(([^)]+)\)'))
match<Match>(new RegExp(r'\(([^\n)]+)\)([^/]+)?'))
.value((r) => r.scanner.lastMatch);
static final Parser<Match> parameterName = match<Match>(
new RegExp('$notSlashRgx?' r':([A-Za-z0-9_]+)' '$notSlashRgx?'))
new RegExp('$notSlashRgx?' r':([A-Za-z0-9_]+)' r'([^(/\n])?'))
.value((r) => r.scanner.lastMatch);
static final Parser<ParameterSegment> parameterSegment = chain([
@ -23,13 +21,16 @@ class RouteGrammar {
]).map((r) {
var match = r.value[0] as Match;
var rgxMatch = r.value[2] as Match;
var pre = match[1] ?? '';
var post = match[3] ?? '';
RegExp rgx;
if (rgxMatch != null) {
rgx = RegExp(rgxMatch[1]);
var pre = match[1] ?? '';
var post = rgxMatch[2] ?? '';
post += match[3] ?? '';
rgx = RegExp('(${rgxMatch[1]})');
post = (rgxMatch[2] ?? '') + post;
}
if (pre.isNotEmpty || post.isNotEmpty) {
if (rgx != null) {
var pattern = pre + rgx.pattern + post;
@ -38,7 +39,6 @@ class RouteGrammar {
rgx = RegExp('$pre$notSlashRgx$post');
}
}
}
var s = new ParameterSegment(match[2], rgx);
return r.value[1] == true ? new OptionalSegment(s) : s;

View file

@ -1,6 +1,6 @@
name: angel_route
description: A powerful, isomorphic routing library for Dart. It is mainly used in the Angel framework, but can be used in Flutter and on the Web.
version: 3.0.2
version: 3.0.3
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_route
environment: