This commit is contained in:
Tobe O 2018-06-03 21:46:44 -04:00
parent 1c5e572688
commit 555b028ac1
15 changed files with 37 additions and 83 deletions

4
.gitignore vendored
View file

@ -71,3 +71,7 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties
.idea
.dart_tool
*.iml

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -1,28 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>General</id>
</State>
<State>
<id>XPath</id>
</State>
</expanded-state>
<selected-state>
<State>
<id>AngularJS</id>
</State>
</selected-state>
</profile-state>
</entry>
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/angel_route.iml" filepath="$PROJECT_DIR$/.idea/angel_route.iml" />
<module fileurl="file://$PROJECT_DIR$/route.iml" filepath="$PROJECT_DIR$/route.iml" />
</modules>
</component>
</project>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test" />
<option name="scope" value="FOLDER" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Navigate Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/navigate_test.dart" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Params Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/params_test.dart" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Server Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/server_test.dart" />
<method />
</configuration>
</component>

View file

@ -1 +1,4 @@
language: dart
dart:
- dev
- stable

2
CHANGELOG.md Normal file
View file

@ -0,0 +1,2 @@
# 2.0.5
* Patch to work with `combinator@1.0.0`.

View file

@ -1,9 +1,11 @@
part of angel_route.src.router;
class RouteGrammar {
static final RegExp rgx = new RegExp(r'\((.+)\)');
static final Parser<String> notSlash =
match(new RegExp(r'[^/]+')).value((r) => r.span.text);
static final Parser<RegExp> regExp = new _RegExpParser();
static final Parser<RegExp> regExp =
match(rgx).map((r) => new RegExp(r.scanner.lastMatch[1]));
static final Parser<String> parameterName =
match(new RegExp(r':([A-Za-z0-9_]+)'))
.value((r) => r.span.text.substring(1));
@ -32,6 +34,7 @@ class RouteGrammar {
.surroundedBy(match('/').star().opt());
}
/*
class _RegExpParser extends Parser<RegExp> {
static final RegExp rgx = new RegExp(r'\((.+)\)');
@ -41,7 +44,7 @@ class _RegExpParser extends Parser<RegExp> {
return new ParseResult(this, true, [],
span: scanner.lastSpan, value: new RegExp(scanner.lastMatch[1]));
}
}
}*/
class RouteDefinition {
final List<RouteSegment> segments;
@ -66,6 +69,7 @@ class RouteDefinition {
abstract class RouteSegment {
Parser<Map<String, dynamic>> compile(bool isLast);
Parser<Map<String, dynamic>> compileNext(
Parser<Map<String, dynamic>> p, bool isLast);
}

View file

@ -14,7 +14,7 @@ class Route {
: _routeDefinition = RouteGrammar.routeDefinition
.parse(new SpanScanner(path.replaceAll(_straySlashes, '')))
.value {
if (_routeDefinition.segments.isEmpty) _parser = match('').value((r) => {});
if (_routeDefinition?.segments?.isNotEmpty != true) _parser = match('').value((r) => {});
}
factory Route.join(Route a, Route b) {

View file

@ -10,12 +10,12 @@ part 'symlink_route.dart';
part 'route.dart';
part 'routing_result.dart';
final RegExp _param = new RegExp(r':([A-Za-z0-9_]+)(\((.+)\))?');
/*final RegExp _param = new RegExp(r':([A-Za-z0-9_]+)(\((.+)\))?');
final RegExp _rgxEnd = new RegExp(r'\$+$');
final RegExp _rgxStart = new RegExp(r'^\^+');
final RegExp _rgxStraySlashes =
new RegExp(r'(^((\\+/)|(/))+)|(((\\+/)|(/))+$)');
final RegExp _slashDollar = new RegExp(r'/+\$');
final RegExp _slashDollar = new RegExp(r'/+\$');*/
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
/// An abstraction over complex [Route] trees. Use this instead of the raw API. :)

View file

@ -1,13 +1,17 @@
name: angel_route
description: A powerful, isomorphic routing library for Dart.
version: 2.0.4
version: 2.0.5
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_route
environment:
sdk: ">=1.19.0"
sdk: ">=1.19.0 <3.0.0"
dependencies:
combinator: ^1.0.0-beta
combinator: ^1.0.0
meta: ^1.0.0
path: ^1.0.0
string_scanner: ^1.0.0
dev_dependencies:
browser: ">=0.10.0 < 0.11.0"
dart2_constant: ^1.0.0
http: ">=0.11.3 <0.12.0"
test: ">=0.12.15 <0.13.0"

View file

@ -1,6 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:angel_route/angel_route.dart';
import 'package:dart2_constant/convert.dart';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
@ -27,7 +27,7 @@ main() {
router.group('/people', (router) {
router.get('/', (req, res) {
res.write(JSON.encode(people));
res.write(json.encode(people));
return false;
});
@ -35,14 +35,14 @@ main() {
router.get('/', (req, res) {
// In a real application, we would take the param,
// but not here...
res.write(JSON.encode(people.first));
res.write(json.encode(people.first));
return false;
});
router.get('/name', (req, res) {
// In a real application, we would take the param,
// but not here...
res.write(JSON.encode(people.first['name']));
res.write(json.encode(people.first['name']));
return false;
});
});
@ -76,7 +76,7 @@ main() {
client = new http.Client();
router.dumpTree();
server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0);
server = await HttpServer.bind('127.0.0.1', 0);
url = 'http://${server.address.address}:${server.port}';
server.listen((req) async {
@ -129,20 +129,20 @@ main() {
test('root', () async {
final res = await client.get('$url/people');
print('Response: ${res.body}');
expect(JSON.decode(res.body), equals(people));
expect(json.decode(res.body), equals(people));
});
group('param', () {
test('root', () async {
final res = await client.get('$url/people/0');
print('Response: ${res.body}');
expect(JSON.decode(res.body), equals(people.first));
expect(json.decode(res.body), equals(people.first));
});
test('path', () async {
final res = await client.get('$url/people/0/name');
print('Response: ${res.body}');
expect(JSON.decode(res.body), equals(people.first['name']));
expect(json.decode(res.body), equals(people.first['name']));
});
});
});