From f7245030cbd28d5ee62adfbc6a8f4379d7bc145b Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 27 Jun 2018 20:46:34 -0400 Subject: [PATCH] Bump to 1.0.6 --- jael/CHANGELOG.md | 5 ++ jael/lib/src/renderer.dart | 23 +++++--- jael/pubspec.yaml | 2 +- jael/test/render/custom_element_test.dart | 64 +++++++++++++++++++++-- 4 files changed, 82 insertions(+), 12 deletions(-) diff --git a/jael/CHANGELOG.md b/jael/CHANGELOG.md index c5c134d0..afc85072 100644 --- a/jael/CHANGELOG.md +++ b/jael/CHANGELOG.md @@ -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. diff --git a/jael/lib/src/renderer.dart b/jael/lib/src/renderer.dart index 8218372e..4bbd317b 100644 --- a/jael/lib/src/renderer.dart +++ b/jael/lib/src/renderer.dart @@ -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, diff --git a/jael/pubspec.yaml b/jael/pubspec.yaml index 29e97fed..6a117de5 100644 --- a/jael/pubspec.yaml +++ b/jael/pubspec.yaml @@ -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 homepage: https://github.com/angel-dart/jael/tree/master/jael diff --git a/jael/test/render/custom_element_test.dart b/jael/test/render/custom_element_test.dart index 6b2f6932..4c09aabf 100644 --- a/jael/test/render/custom_element_test.dart +++ b/jael/test/render/custom_element_test.dart @@ -7,13 +7,67 @@ import 'package:test/test.dart'; void main() { test('render into div', () { var template = ''' - - The square root of {{ n }} is {{ sqrt(n) }}. - - +
+ + The square root of {{ n }} is {{ sqrt(n).toInt() }}. + + +
'''; var html = render(template, {'sqrt': sqrt}); + print(html); + + expect(html, ''' +
+
+ The square root of 16 is 4. +
+
+ '''.trim()); + }); + + test('render into explicit tag name', () { + var template = ''' +
+ + The square root of {{ n }} is {{ sqrt(n).toInt() }}. + + +
+ '''; + + var html = render(template, {'sqrt': sqrt}); + print(html); + + expect(html, ''' +
+ + The square root of 16 is 4. + +
+ '''.trim()); + }); + + test('render without tag name', () { + var template = ''' +
+ + The square root of {{ n }} is {{ sqrt(n).toInt() }}. + + +
+ '''; + + var html = render(template, {'sqrt': sqrt}); + print(html); + + expect(html, ''' +
+ The square root of 16 is 4. + +
+ '''.trim()); }); } @@ -22,4 +76,4 @@ String render(String template, [Map values]) { var buffer = new CodeBuffer(); const jael.Renderer().render(doc, buffer, new SymbolTable(values: values)); return buffer.toString(); -} \ No newline at end of file +}