Bump to 1.0.6
This commit is contained in:
parent
bdd94d5796
commit
f7245030cb
4 changed files with 82 additions and 12 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -107,11 +107,15 @@ 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) {
|
||||
} 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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,13 +7,67 @@ import 'package:test/test.dart';
|
|||
void main() {
|
||||
test('render into div', () {
|
||||
var template = '''
|
||||
<div>
|
||||
<element name="square-root">
|
||||
The square root of {{ n }} is {{ sqrt(n) }}.
|
||||
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
|
||||
</element>
|
||||
<square-root n="16" />
|
||||
<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());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue