1.0.2
This commit is contained in:
parent
919c9915dd
commit
1ebef65a60
3 changed files with 58 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
# 1.0.2
|
||||||
|
* Use `package:dart2_constant`.
|
||||||
|
* Upgrade `package:symbol_table`.
|
||||||
|
* Added `Renderer.errorDocument`.
|
||||||
|
|
||||||
# 1.0.1
|
# 1.0.1
|
||||||
* Reworked the scanner; thereby fixing an extremely pesky bug
|
* Reworked the scanner; thereby fixing an extremely pesky bug
|
||||||
that prevented successful parsing of Jael files containing
|
that prevented successful parsing of Jael files containing
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:code_buffer/code_buffer.dart';
|
import 'package:code_buffer/code_buffer.dart';
|
||||||
|
import 'package:dart2_constant/convert.dart';
|
||||||
import 'package:symbol_table/symbol_table.dart';
|
import 'package:symbol_table/symbol_table.dart';
|
||||||
import 'ast/ast.dart';
|
import 'ast/ast.dart';
|
||||||
import 'text/parser.dart';
|
import 'text/parser.dart';
|
||||||
|
@ -29,12 +29,58 @@ Document parseDocument(String text,
|
||||||
class Renderer {
|
class Renderer {
|
||||||
const Renderer();
|
const Renderer();
|
||||||
|
|
||||||
|
/// Render an error page.
|
||||||
|
static void errorDocument(Iterable<JaelError> errors, CodeBuffer buf) {
|
||||||
|
buf
|
||||||
|
..writeln('<!DOCTYPE html>')
|
||||||
|
..writeln('<html lang="en">')
|
||||||
|
..indent()
|
||||||
|
..writeln('<head>')
|
||||||
|
..indent()
|
||||||
|
..writeln(
|
||||||
|
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
||||||
|
)
|
||||||
|
..writeln('<title>${errors.length} Error(s)</title>')
|
||||||
|
..outdent()
|
||||||
|
..writeln('</head>')
|
||||||
|
..writeln('<body>')
|
||||||
|
..writeln('<h1>${errors.length} Error(s)</h1>')
|
||||||
|
..writeln('<ul>')
|
||||||
|
..indent();
|
||||||
|
|
||||||
|
for (var error in errors) {
|
||||||
|
var type =
|
||||||
|
error.severity == JaelErrorSeverity.warning ? 'warning' : 'error';
|
||||||
|
buf
|
||||||
|
..writeln('<li>')
|
||||||
|
..indent()
|
||||||
|
..writeln(
|
||||||
|
'<b>$type:</b> ${error.span.start.toolString}: ${error.message}')
|
||||||
|
..writeln('<br>')
|
||||||
|
..writeln(
|
||||||
|
'<span style="color: red;">' +
|
||||||
|
htmlEscape
|
||||||
|
.convert(error.span.highlight(color: false))
|
||||||
|
.replaceAll('\n', '<br>') +
|
||||||
|
'</span>',
|
||||||
|
)
|
||||||
|
..outdent()
|
||||||
|
..writeln('</li>');
|
||||||
|
}
|
||||||
|
|
||||||
|
buf
|
||||||
|
..outdent()
|
||||||
|
..writeln('</ul>')
|
||||||
|
..writeln('</body>')
|
||||||
|
..writeln('</html>');
|
||||||
|
}
|
||||||
|
|
||||||
/// Renders a [document] into the [buffer] as HTML.
|
/// Renders a [document] into the [buffer] as HTML.
|
||||||
///
|
///
|
||||||
/// If [strictResolution] is `false` (default: `true`), then undefined identifiers will return `null`
|
/// If [strictResolution] is `false` (default: `true`), then undefined identifiers will return `null`
|
||||||
/// instead of throwing.
|
/// instead of throwing.
|
||||||
void render(Document document, CodeBuffer buffer, SymbolTable scope, {bool strictResolution: true}) {
|
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);
|
if (document.doctype != null) buffer.writeln(document.doctype.span.text);
|
||||||
renderElement(
|
renderElement(
|
||||||
|
@ -87,7 +133,7 @@ class Renderer {
|
||||||
msg = value.toString();
|
msg = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.write(attribute.isRaw ? msg : HTML_ESCAPE.convert(msg));
|
buffer.write(attribute.isRaw ? msg : htmlEscape.convert(msg));
|
||||||
buffer.write('"');
|
buffer.write('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +221,7 @@ class Renderer {
|
||||||
void renderDeclare(
|
void renderDeclare(
|
||||||
Element element, CodeBuffer buffer, SymbolTable scope, bool html5) {
|
Element element, CodeBuffer buffer, SymbolTable scope, bool html5) {
|
||||||
for (var attribute in element.attributes) {
|
for (var attribute in element.attributes) {
|
||||||
scope.add(attribute.name,
|
scope.create(attribute.name,
|
||||||
value: attribute.value?.compute(scope), constant: true);
|
value: attribute.value?.compute(scope), constant: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +285,7 @@ class Renderer {
|
||||||
if (child.isRaw)
|
if (child.isRaw)
|
||||||
buffer.write(value);
|
buffer.write(value);
|
||||||
else
|
else
|
||||||
buffer.write(HTML_ESCAPE.convert(value.toString()));
|
buffer.write(htmlEscape.convert(value.toString()));
|
||||||
}
|
}
|
||||||
} else if (child is Element) {
|
} else if (child is Element) {
|
||||||
if (buffer?.lastLine?.text?.isNotEmpty == true) buffer.writeln();
|
if (buffer?.lastLine?.text?.isNotEmpty == true) buffer.writeln();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: jael
|
name: jael
|
||||||
version: 1.0.1
|
version: 1.0.2
|
||||||
description: A simple server-side HTML templating engine for Dart.
|
description: A simple server-side HTML templating engine for Dart.
|
||||||
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
|
||||||
|
@ -8,6 +8,7 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
charcode: ^1.0.0
|
charcode: ^1.0.0
|
||||||
code_buffer: ^1.0.0
|
code_buffer: ^1.0.0
|
||||||
|
dart2_constant: ^1.0.0
|
||||||
source_span: ^1.0.0
|
source_span: ^1.0.0
|
||||||
string_scanner: ^1.0.0
|
string_scanner: ^1.0.0
|
||||||
symbol_table: ^1.0.0
|
symbol_table: ^1.0.0
|
||||||
|
|
Loading…
Reference in a new issue