Migrated angel_jael

This commit is contained in:
thomashii@dukefirehawk.com 2021-04-30 15:19:26 +08:00
parent 750dd63309
commit 9553e41a2b
4 changed files with 37 additions and 28 deletions

View file

@ -21,7 +21,7 @@
* Added symbol_table and migrated to 2.0.0 (16/16 tests passed)
* Migrated jael to 4.0.0 (20/20 tests passed)
* Migrated jael_preprocessor to 3.0.0 (5/5 tests passed)
* Updated angel_jael to 3.0.0 (in progress)
* Migrated angel_jael to 4.0.0 (1/1 test passed)
* Updated pub_sub to 3.0.0 (in progress)
* Updated production to 2.0.0 (in progress)
* Updated hot to 3.0.0 (in progress)

View file

@ -12,33 +12,33 @@ import 'package:symbol_table/symbol_table.dart';
///
/// To apply additional transforms to parsed documents, provide a set of [patch] functions.
AngelConfigurer jael(Directory viewsDirectory,
{String fileExtension,
bool strictResolution: false,
bool cacheViews: false,
Iterable<Patcher> patch,
bool asDSX: false,
CodeBuffer createBuffer()}) {
var cache = <String, Document>{};
{String? fileExtension,
bool strictResolution = false,
bool cacheViews = false,
Iterable<Patcher>? patch,
bool asDSX = false,
CodeBuffer createBuffer()?}) {
var cache = <String, Document?>{};
fileExtension ??= '.jael';
createBuffer ??= () => new CodeBuffer();
return (Angel app) async {
app.viewGenerator = (String name, [Map locals]) async {
app.viewGenerator = (String name, [Map? locals]) async {
var errors = <JaelError>[];
Document processed;
Document? processed;
if (cacheViews == true && cache.containsKey(name)) {
processed = cache[name];
} else {
var file = viewsDirectory.childFile(name + fileExtension);
var file = viewsDirectory.childFile(name + fileExtension!);
var contents = await file.readAsString();
var doc = parseDocument(contents,
sourceUrl: file.uri, asDSX: asDSX == true, onError: errors.add);
sourceUrl: file.uri, asDSX: asDSX == true, onError: errors.add)!;
processed = doc;
try {
processed = await resolve(doc, viewsDirectory,
patch: patch, onError: errors.add);
processed = await (resolve(doc, viewsDirectory,
patch: patch, onError: errors.add));
} catch (_) {
// Ignore these errors, so that we can show syntax errors.
}
@ -48,15 +48,15 @@ AngelConfigurer jael(Directory viewsDirectory,
}
}
var buf = createBuffer();
var scope = new SymbolTable(
values: locals?.keys?.fold<Map<String, dynamic>>(<String, dynamic>{},
var buf = createBuffer!();
var scope = SymbolTable(
values: locals?.keys.fold<Map<String, dynamic>>(<String, dynamic>{},
(out, k) => out..[k.toString()] = locals[k]) ??
<String, dynamic>{});
if (errors.isEmpty) {
try {
const Renderer().render(processed, buf, scope,
const Renderer().render(processed!, buf, scope,
strictResolution: strictResolution == true);
return buf.toString();
} on JaelError catch (e) {

View file

@ -1,35 +1,44 @@
name: angel_jael
version: 3.0.0
version: 4.0.0
description: Angel support for the Jael templating engine, similar to Blade or Liquid.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/jael/tree/master/jael
publish_to: none
environment:
sdk: '>=2.10.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel_framework:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/framework
code_buffer: ^1.0.0
file: ^6.0.0
code_buffer:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/code_buffer
jael:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/jael/jael
jael_preprocessor:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/jael/jael_preprocessor
symbol_table: ^2.0.0
symbol_table:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/symbol_table
file: ^6.0.0
dev_dependencies:
angel_test:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
ref: sdk-2.12.x_nnbd
path: packages/test
html: ^0.15.0
test: ^1.15.7

View file

@ -11,7 +11,7 @@ main() {
// because those packages are already tested.
//
// Instead, just test that we can render at all.
TestClient client;
late TestClient client;
setUp(() async {
var app = new Angel();