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
|
# 1.0.5
|
||||||
* Add support for DSX, a port of JSX to Dart.
|
* Add support for DSX, a port of JSX to Dart.
|
||||||
|
|
||||||
|
|
|
@ -107,11 +107,15 @@ 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 =
|
||||||
|
scope.resolve(customElementName(element.tagName.name))?.value;
|
||||||
|
|
||||||
|
if (customElementValue is Element) {
|
||||||
renderCustomElement(element, buffer, childScope, html5);
|
renderCustomElement(element, buffer, childScope, html5);
|
||||||
return;
|
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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 = '''
|
||||||
|
<div>
|
||||||
<element name="square-root">
|
<element name="square-root">
|
||||||
The square root of {{ n }} is {{ sqrt(n) }}.
|
The square root of {{ n }} is {{ sqrt(n).toInt() }}.
|
||||||
</element>
|
</element>
|
||||||
<square-root n="16" />
|
<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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue