Bump to 1.0.6

This commit is contained in:
Tobe O 2018-06-27 20:46:34 -04:00
parent bdd94d5796
commit f7245030cb
4 changed files with 82 additions and 12 deletions

View file

@ -1,3 +1,8 @@
# 1.0.6
* Add `index-as` to `for-each`.
* Support registering + rendering custom elements.
* Improve handling of booleans in non-strict mode.
# 1.0.5
* Add support for DSX, a port of JSX to Dart.

View file

@ -107,10 +107,14 @@ class Renderer {
} else if (element.tagName.name == 'element') {
registerCustomElement(element, buffer, childScope, html5);
return;
} else if (scope.resolve(customElementName(element.tagName.name))?.value
is Element) {
renderCustomElement(element, buffer, childScope, html5);
return;
} else {
var customElementValue =
scope.resolve(customElementName(element.tagName.name))?.value;
if (customElementValue is Element) {
renderCustomElement(element, buffer, childScope, html5);
return;
}
}
buffer..write('<')..write(element.tagName.name);
@ -207,7 +211,13 @@ class Renderer {
Element element, CodeBuffer buffer, SymbolTable scope, bool html5) {
var attribute = element.attributes.singleWhere((a) => a.name == 'if');
if (attribute.value.compute(scope) != true) return;
var v = attribute.value.compute(scope) as bool;
if (scope.resolve('!strict!')?.value == false) {
v = v == true;
}
if (!v) return;
var otherAttributes = element.attributes.where((a) => a.name != 'if');
Element strippedElement;
@ -325,7 +335,8 @@ class Renderer {
}
try {
scope.create(customElementName(name), value: element, constant: true);
var p = scope.isRoot ? scope : scope.parent;
p.create(customElementName(name), value: element, constant: true);
} on StateError {
throw new JaelError(
JaelErrorSeverity.error,

View file

@ -1,5 +1,5 @@
name: jael
version: 1.0.5
version: 1.0.6
description: A simple server-side HTML templating engine for Dart.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/jael/tree/master/jael

View file

@ -7,13 +7,67 @@ import 'package:test/test.dart';
void main() {
test('render into div', () {
var template = '''
<element name="square-root">
The square root of {{ n }} is {{ sqrt(n) }}.
</element>
<square-root n="16" />
<div>
<element name="square-root">
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
</element>
<square-root n=16 />
</div>
''';
var html = render(template, {'sqrt': sqrt});
print(html);
expect(html, '''
<div>
<div>
The square root of 16 is 4.
</div>
</div>
'''.trim());
});
test('render into explicit tag name', () {
var template = '''
<div>
<element name="square-root">
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
</element>
<square-root as="span" n=16 />
</div>
''';
var html = render(template, {'sqrt': sqrt});
print(html);
expect(html, '''
<div>
<span>
The square root of 16 is 4.
</span>
</div>
'''.trim());
});
test('render without tag name', () {
var template = '''
<div>
<element name="square-root">
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
</element>
<square-root as=false n=16 />
</div>
''';
var html = render(template, {'sqrt': sqrt});
print(html);
expect(html, '''
<div>
The square root of 16 is 4.
</div>
'''.trim());
});
}
@ -22,4 +76,4 @@ String render(String template, [Map<String, dynamic> values]) {
var buffer = new CodeBuffer();
const jael.Renderer().render(doc, buffer, new SymbolTable(values: values));
return buffer.toString();
}
}