angel_jael@2.0.0

This commit is contained in:
Tobe O 2018-11-10 16:48:03 -05:00
parent 644722dc69
commit d99aa932a9
8 changed files with 33 additions and 24 deletions

View file

@ -1,3 +1,7 @@
# 2.0.0
* Angel 2 and Dart 2 updates.
* Default to `.jael` instead of `.jl`.
# 1.0.3 # 1.0.3
* Update for annoying map casting bug. * Update for annoying map casting bug.

View file

@ -62,7 +62,7 @@ main() async {
jael(fileSystem.directory('views')), jael(fileSystem.directory('views')),
); );
// Render the contents of views/index.jl // Render the contents of views/index.jael
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'})); app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));
app.use(() => throw new AngelHttpException.notFound()); app.use(() => throw new AngelHttpException.notFound());

View file

@ -1,11 +1,12 @@
import 'dart:convert';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_jael/angel_jael.dart'; import 'package:angel_jael/angel_jael.dart';
import 'package:dart2_constant/convert.dart';
import 'package:file/local.dart'; import 'package:file/local.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
main() async { main() async {
var app = new Angel()..lazyParseBodies = true; var app = new Angel();
var http = new AngelHttp(app); var http = new AngelHttp(app);
var fileSystem = const LocalFileSystem(); var fileSystem = const LocalFileSystem();
@ -13,11 +14,13 @@ main() async {
jael(fileSystem.directory('views')), jael(fileSystem.directory('views')),
); );
app.get('/', app.get(
(res) => res.render('index', {'title': 'Sample App', 'message': null})); '/',
(req, res) =>
res.render('index', {'title': 'Sample App', 'message': null}));
app.post('/', (RequestContext req, res) async { app.post('/', (RequestContext req, res) async {
var body = await req.lazyBody(); var body = await req.parseBody();
print('Body: $body'); print('Body: $body');
var msg = body['message'] ?? '<unknown>'; var msg = body['message'] ?? '<unknown>';
return await res.render('index', { return await res.render('index', {
@ -27,7 +30,7 @@ main() async {
}); });
}); });
app.use(() => throw new AngelHttpException.notFound()); app.fallback((req, res) => throw new AngelHttpException.notFound());
app.logger = new Logger('angel') app.logger = new Logger('angel')
..onRecord.listen((rec) { ..onRecord.listen((rec) {
@ -36,6 +39,6 @@ main() async {
if (rec.stackTrace != null) print(rec.stackTrace); if (rec.stackTrace != null) print(rec.stackTrace);
}); });
var server = await http.startServer(null, 3000); var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}'); print('Listening at http://${server.address.address}:${server.port}');
} }

View file

@ -19,7 +19,7 @@ AngelConfigurer jael(Directory viewsDirectory,
bool asDSX: false, bool asDSX: false,
CodeBuffer createBuffer()}) { CodeBuffer createBuffer()}) {
var cache = <String, Document>{}; var cache = <String, Document>{};
fileExtension ??= '.jl'; fileExtension ??= '.jael';
createBuffer ??= () => new CodeBuffer(); createBuffer ??= () => new CodeBuffer();
return (Angel app) async { return (Angel app) async {

View file

@ -1,6 +1,6 @@
name: angel_jael name: angel_jael
version: 2.0.0 version: 2.0.0
description: Angel support for the Jael templating engine. description: Angel support for the Jael templating engine, similar to Blade or Liquid.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/jael/tree/master/jael homepage: https://github.com/angel-dart/jael/tree/master/jael
environment: environment:
@ -9,9 +9,10 @@ dependencies:
angel_framework: ^2.0.0-alpha angel_framework: ^2.0.0-alpha
code_buffer: ^1.0.0 code_buffer: ^1.0.0
file: ^5.0.0 file: ^5.0.0
jael: ^1.0.0-alpha jael: ^2.0.0
jael_preprocessor: ^1.0.0-alpha jael_preprocessor: ^2.0.0
symbol_table: ^2.0.0 symbol_table: ^2.0.0
dev_dependencies: dev_dependencies:
angel_test: ^2.0.0-alpha angel_test: ^2.0.0-alpha
html:
test: ^1.0.0 test: ^1.0.0

View file

@ -2,6 +2,7 @@ import 'package:angel_framework/angel_framework.dart';
import 'package:angel_jael/angel_jael.dart'; import 'package:angel_jael/angel_jael.dart';
import 'package:angel_test/angel_test.dart'; import 'package:angel_test/angel_test.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:html/parser.dart' as html;
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
@ -19,7 +20,7 @@ main() {
var fileSystem = new MemoryFileSystem(); var fileSystem = new MemoryFileSystem();
var viewsDirectory = fileSystem.directory('views')..createSync(); var viewsDirectory = fileSystem.directory('views')..createSync();
viewsDirectory.childFile('layout.jl').writeAsStringSync(''' viewsDirectory.childFile('layout.jael').writeAsStringSync('''
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -33,13 +34,14 @@ main() {
</html> </html>
'''); ''');
viewsDirectory.childFile('github.jl').writeAsStringSync(''' viewsDirectory.childFile('github.jael').writeAsStringSync('''
<extend src="layout.jl"> <extend src="layout.jael">
<block name="content">{{username}}</block> <block name="content">{{username}}</block>
</extend> </extend>
'''); ''');
app.get('/github/:username', (String username, ResponseContext res) { app.get('/github/:username', (req, res) {
var username = req.params['username'];
return res.render('github', {'username': username}); return res.render('github', {'username': username});
}); });
@ -47,7 +49,7 @@ main() {
jael(viewsDirectory), jael(viewsDirectory),
); );
app.use(() => throw new AngelHttpException.notFound()); app.fallback((req, res) => throw new AngelHttpException.notFound());
app.logger = new Logger('angel') app.logger = new Logger('angel')
..onRecord.listen((rec) { ..onRecord.listen((rec) {
@ -62,11 +64,10 @@ main() {
test('can render', () async { test('can render', () async {
var response = await client.get('/github/thosakwe'); var response = await client.get('/github/thosakwe');
print('Body:\n${response.body}'); print('Body:\n${response.body}');
expect( expect(
response, html.parse(response.body).outerHtml,
hasBody(''' html
<!DOCTYPE html> .parse('''
<html> <html>
<head> <head>
<title> <title>
@ -76,8 +77,8 @@ main() {
<body> <body>
thosakwe thosakwe
</body> </body>
</html> </html>'''
''' .trim())
.trim())); .outerHtml);
}); });
} }