This commit is contained in:
Tobe O 2019-04-11 12:19:12 -04:00
parent 5fdad82fee
commit deccd61505
6 changed files with 25 additions and 15 deletions

View file

@ -1,2 +1,3 @@
# 2.0.0
* Angel 2 + Dart 2 updates.
* Angel 2 + Dart 2 updates.
* Use `package:file`.

View file

@ -17,13 +17,15 @@ dependencies:
```
# Usage
It's very straightforward to configure an Angel server to use Markdown:
It's very straightforward to configure an Angel server to use Markdown.
Keep in mind to use `package:file` instead of `dart:io`:
```dart
configureServer(Angel app) async {
var fs = LocalFileSystem();
await app.configure(markdown(
// The directory where your views are located.
new Directory('views'),
fs.directory('views'),
));
}
```
@ -73,7 +75,7 @@ configureServer(Angel app) async {
await app.configure(
markdown(
// The directory where your views are located.
new Directory('views'), template: (content, Map locals) {
fs.directory('views'), template: (content, Map locals) {
return '''<!DOCTYPE html>
<html>
<head>

View file

@ -1,2 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode: true
strong-mode:
implicit-casts: false

View file

@ -1,19 +1,23 @@
import 'dart:async';
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_markdown/angel_markdown.dart';
import 'package:file/local.dart';
main() async {
var app = await createServer();
var server = await app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
var http = AngelHttp(app);
var server = await http.startServer(InternetAddress.loopbackIPv4, 3000);
print('Listening at http://${server.address.address}:${server.port}');
}
Future<Angel> createServer() async {
// Create a new server, and install the Markdown renderer.
var app = new Angel();
var fs = LocalFileSystem();
await app
.configure(markdown(new Directory('views'), template: (content, locals) {
.configure(markdown(fs.directory('views'), template: (content, locals) {
return '''
<!DOCTYPE html>
<html>
@ -38,7 +42,7 @@ Future<Angel> createServer() async {
}));
// Compile a landing page
app.get('/', (res) => res.render('hello', {'title': 'Welcome'}));
app.get('/', (req, res) => res.render('hello', {'title': 'Welcome'}));
return app;
}

View file

@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:mirrors';
import 'package:angel_framework/angel_framework.dart';
import 'package:file/file.dart';
import 'package:markdown/markdown.dart';
final RegExp _braces = new RegExp(r'@?{{(((\\})|([^}]))+)}}');
@ -18,15 +18,15 @@ AngelConfigurer markdown(
Directory viewsDirectory, {
String extension,
ExtensionSet extensionSet,
FutureOr<String> template(String content, Map locals),
FutureOr<String> template(String content, Map<String, dynamic> locals),
}) {
extension ??= '.md';
extensionSet ??= ExtensionSet.gitHub;
extensionSet ??= ExtensionSet.gitHubWeb;
return (Angel app) async {
app.viewGenerator = (String name, [Map locals]) async {
var file =
new File.fromUri(viewsDirectory.uri.resolve('$name$extension'));
app.viewGenerator = (String name, [Map<String, dynamic> locals]) async {
var file = viewsDirectory.childFile(
viewsDirectory.fileSystem.path.setExtension(name, extension));
var contents = await file.readAsString();
contents = contents.replaceAllMapped(_braces, (m) {
@ -40,7 +40,7 @@ AngelConfigurer markdown(
var split = expr.split('.');
var root = split[0];
if (!locals?.containsKey(root) == true)
if (locals?.containsKey(root) != true)
throw new UnimplementedError(
'Expected a local named "$root", but none was provided. Expression text: "$text"');

View file

@ -7,6 +7,7 @@ environment:
sdk: ">=2.0.0-dev <3.0.0"
dependencies:
angel_framework: ^2.0.0-alpha
file: ^5.0.0
markdown: ^2.0.0
dev_dependencies:
angel_test: ^2.0.0