Permalink
Browse files

for loop should be able to loop over values and filtered variables too.

Related, added test to prove that issue #99 is fixed.
  • Loading branch information...
1 parent 3adbef5 commit d77195d5216cea53b5f4e89f0cfc54bfe694773c @kaos kaos committed Dec 4, 2013
Showing with 12 additions and 3 deletions.
  1. +2 −2 src/erlydtl_parser.yrl
  2. +10 −1 tests/src/erlydtl_unittests.erl
View
@@ -296,8 +296,8 @@ ForBlock -> ForBraced Elements EmptyBraced Elements EndForBraced : {for, '$1', '
EmptyBraced -> open_tag empty_keyword close_tag.
ForBraced -> open_tag for_keyword ForExpression close_tag : '$3'.
EndForBraced -> open_tag endfor_keyword close_tag.
-ForExpression -> ForGroup in_keyword Variable : {'in', '$1', '$3', false}.
-ForExpression -> ForGroup in_keyword Variable reversed_keyword : {'in', '$1', '$3', true}.
+ForExpression -> ForGroup in_keyword Value : {'in', '$1', '$3', false}.
+ForExpression -> ForGroup in_keyword Value reversed_keyword : {'in', '$1', '$3', true}.
ForGroup -> identifier : ['$1'].
ForGroup -> ForGroup ',' identifier : '$1' ++ ['$3'].
@@ -279,7 +279,16 @@ tests() ->
<<"{% for x in list %}{% ifchanged x.name|first %}{{ x.value }}{% endifchanged %}\n{% endfor %}">>,
[{'list', [[{"name", ["nA","nB"]},{"value","1"}],[{"name", ["nA","nC"]},{"value","2"}],
[{"name", ["nB","nC"]},{"value","3"}],[{"name", ["nB","nA"]},{"value","4"}]]}],
- <<"1\n\n3\n\n">>}
+ <<"1\n\n3\n\n">>},
+
+ {"Loop undefined var",
+ <<"{% for i in undef %}i = {{ i }}.\n{% endfor %}">>,
+ [],
+ <<"">>},
+ {"Loop filtered value rather than variable",
+ <<"{% for x in 123|make_list %}{% if not forloop.first %}, {% endif %}{{ x }}{% endfor %}">>,
+ [],
+ <<"1, 2, 3">>}
]},
{"for/empty", [
{"Simple loop",

0 comments on commit d77195d

Please sign in to comment.