From f811dfcd809d1dda83f94cb63ff2cbe202d3a0c2 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 27 Jun 2018 19:52:12 -0400 Subject: [PATCH] Add index-as to for-each --- jael/lib/src/renderer.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jael/lib/src/renderer.dart b/jael/lib/src/renderer.dart index a7299eb5..5a5c9251 100644 --- a/jael/lib/src/renderer.dart +++ b/jael/lib/src/renderer.dart @@ -104,6 +104,9 @@ class Renderer { } else if (element.tagName.name == 'switch') { renderSwitch(element, buffer, childScope, html5); return; + } else if (element.tagName.name == 'element') { + registerCustomElement(element, buffer, childScope, html5); + return; } buffer..write('<')..write(element.tagName.name); @@ -166,7 +169,10 @@ class Renderer { var asAttribute = element.attributes .firstWhere((a) => a.name == 'as', orElse: () => null); + var indexAsAttribute = element.attributes + .firstWhere((a) => a.name == 'index-as', orElse: () => null); var alias = asAttribute?.value?.compute(scope) ?? 'item'; + var indexAs = indexAsAttribute?.value?.compute(scope)?.toString() ?? 'item'; var otherAttributes = element.attributes.where((a) => a.name != 'for-each' && a.name != 'as'); Element strippedElement; @@ -186,8 +192,9 @@ class Renderer { element.tagName2, element.gt2); + int i = 0; for (var item in attribute.value.compute(scope)) { - var childScope = scope.createChild(values: {alias: item}); + var childScope = scope.createChild(values: {alias: item, indexAs: i++}); renderElement(strippedElement, buffer, childScope, html5); } }