diff --git a/jael/CHANGELOG.md b/jael/CHANGELOG.md index a87c9287..5f6c1657 100644 --- a/jael/CHANGELOG.md +++ b/jael/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.0.2 +* Use `package:dart2_constant`. +* Upgrade `package:symbol_table`. +* Added `Renderer.errorDocument`. + # 1.0.1 * Reworked the scanner; thereby fixing an extremely pesky bug that prevented successful parsing of Jael files containing diff --git a/jael/lib/src/renderer.dart b/jael/lib/src/renderer.dart index e64e649f..d93f15a5 100644 --- a/jael/lib/src/renderer.dart +++ b/jael/lib/src/renderer.dart @@ -1,5 +1,5 @@ -import 'dart:convert'; import 'package:code_buffer/code_buffer.dart'; +import 'package:dart2_constant/convert.dart'; import 'package:symbol_table/symbol_table.dart'; import 'ast/ast.dart'; import 'text/parser.dart'; @@ -29,12 +29,58 @@ Document parseDocument(String text, class Renderer { const Renderer(); + /// Render an error page. + static void errorDocument(Iterable errors, CodeBuffer buf) { + buf + ..writeln('') + ..writeln('') + ..indent() + ..writeln('') + ..indent() + ..writeln( + '', + ) + ..writeln('${errors.length} Error(s)') + ..outdent() + ..writeln('') + ..writeln('') + ..writeln('

${errors.length} Error(s)

') + ..writeln('') + ..writeln('') + ..writeln(''); + } + /// Renders a [document] into the [buffer] as HTML. /// /// If [strictResolution] is `false` (default: `true`), then undefined identifiers will return `null` /// instead of throwing. void render(Document document, CodeBuffer buffer, SymbolTable scope, {bool strictResolution: true}) { - scope.add('!strict!', value: strictResolution != false); + scope.create('!strict!', value: strictResolution != false); if (document.doctype != null) buffer.writeln(document.doctype.span.text); renderElement( @@ -87,7 +133,7 @@ class Renderer { msg = value.toString(); } - buffer.write(attribute.isRaw ? msg : HTML_ESCAPE.convert(msg)); + buffer.write(attribute.isRaw ? msg : htmlEscape.convert(msg)); buffer.write('"'); } @@ -175,7 +221,7 @@ class Renderer { void renderDeclare( Element element, CodeBuffer buffer, SymbolTable scope, bool html5) { for (var attribute in element.attributes) { - scope.add(attribute.name, + scope.create(attribute.name, value: attribute.value?.compute(scope), constant: true); } @@ -239,7 +285,7 @@ class Renderer { if (child.isRaw) buffer.write(value); else - buffer.write(HTML_ESCAPE.convert(value.toString())); + buffer.write(htmlEscape.convert(value.toString())); } } else if (child is Element) { if (buffer?.lastLine?.text?.isNotEmpty == true) buffer.writeln(); diff --git a/jael/pubspec.yaml b/jael/pubspec.yaml index 9e4d6d96..a78723cf 100644 --- a/jael/pubspec.yaml +++ b/jael/pubspec.yaml @@ -1,5 +1,5 @@ name: jael -version: 1.0.1 +version: 1.0.2 description: A simple server-side HTML templating engine for Dart. author: Tobe O homepage: https://github.com/angel-dart/jael/tree/master/jael @@ -8,6 +8,7 @@ environment: dependencies: charcode: ^1.0.0 code_buffer: ^1.0.0 + dart2_constant: ^1.0.0 source_span: ^1.0.0 string_scanner: ^1.0.0 symbol_table: ^1.0.0