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 # 1.0.5
* Add support for DSX, a port of JSX to Dart. * Add support for DSX, a port of JSX to Dart.

View file

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

View file

@ -1,5 +1,5 @@
name: jael name: jael
version: 1.0.5 version: 1.0.6
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

View file

@ -7,13 +7,67 @@ import 'package:test/test.dart';
void main() { void main() {
test('render into div', () { test('render into div', () {
var template = ''' var template = '''
<element name="square-root"> <div>
The square root of {{ n }} is {{ sqrt(n) }}. <element name="square-root">
</element> The square root of {{ n }} is {{ sqrt(n).toInt() }}.
<square-root n="16" /> </element>
<square-root n=16 />
</div>
'''; ''';
var html = render(template, {'sqrt': sqrt}); 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());
}); });
} }