diff --git a/jael/CHANGELOG.md b/jael/CHANGELOG.md index afc85072..8d4bca78 100644 --- a/jael/CHANGELOG.md +++ b/jael/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.0.6+1 +* Ensure `` pass attributes. + # 1.0.6 * Add `index-as` to `for-each`. * Support registering + rendering custom elements. diff --git a/jael/lib/src/renderer.dart b/jael/lib/src/renderer.dart index fdd7ac8f..910af96d 100644 --- a/jael/lib/src/renderer.dart +++ b/jael/lib/src/renderer.dart @@ -353,8 +353,10 @@ class Renderer { var attrs = element.attributes.where((a) => a.name != 'as'); for (var attribute in attrs) { - scope.create(attribute.name, - value: attribute.value?.compute(scope), constant: true); + if (attribute.name.startsWith('@')) { + scope.create(attribute.name.substring(1), + value: attribute.value?.compute(scope), constant: true); + } } if (renderAs == false) { @@ -369,7 +371,8 @@ class Renderer { var syntheticElement = new RegularElement( template.lt, new SyntheticIdentifier(tagName), - [], + element.attributes + .where((a) => a.name != 'as' && !a.name.startsWith('@')), template.gt, template.children, template.lt2, diff --git a/jael/lib/src/text/scanner.dart b/jael/lib/src/text/scanner.dart index ea8d8ef9..f1beabc6 100644 --- a/jael/lib/src/text/scanner.dart +++ b/jael/lib/src/text/scanner.dart @@ -6,7 +6,7 @@ import '../ast/ast.dart'; final RegExp _whitespace = new RegExp(r'[ \n\r\t]+'); final RegExp _id = - new RegExp(r'(([A-Za-z][A-Za-z0-9_]*-)*([A-Za-z][A-Za-z0-9_]*))'); + new RegExp(r'@?(([A-Za-z][A-Za-z0-9_]*-)*([A-Za-z][A-Za-z0-9_]*))'); final RegExp _string1 = new RegExp( r"'((\\(['\\/bfnrt]|(u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])))|([^'\\]))*'"); final RegExp _string2 = new RegExp( diff --git a/jael/pubspec.yaml b/jael/pubspec.yaml index 6a117de5..8f4c7899 100644 --- a/jael/pubspec.yaml +++ b/jael/pubspec.yaml @@ -1,5 +1,5 @@ name: jael -version: 1.0.6 +version: 1.0.6+1 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 4c09aabf..08aef101 100644 --- a/jael/test/render/custom_element_test.dart +++ b/jael/test/render/custom_element_test.dart @@ -11,7 +11,7 @@ void main() { The square root of {{ n }} is {{ sqrt(n).toInt() }}. - + '''; @@ -33,7 +33,7 @@ void main() { The square root of {{ n }} is {{ sqrt(n).toInt() }}. - + '''; @@ -49,13 +49,35 @@ void main() { '''.trim()); }); + test('pass attributes', () { + 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() }}. - +
''';