Просмотр исходного кода

Fix bug in new scope routine (#101)

When there was some text surrounding the sub scope,
it only kept the last piece.
Tests updated to catch this.
Andreas Stenius 11 лет назад
Родитель
Сommit
c1eebb25f3
2 измененных файлов с 7 добавлено и 2 удалено
  1. 1 1
      src/erlydtl_beam_compiler.erl
  2. 6 1
      tests/src/erlydtl_unittests.erl

+ 1 - 1
src/erlydtl_beam_compiler.erl

@@ -674,7 +674,7 @@ body_ast(DjangoParseTree, TreeWalker) ->
           AstInfoList),
 
     {Ast, TreeWalker3} = end_scope(
-                           fun (AstScope) -> [?Q("begin _@AstScope end")] end,
+                           fun ([ScopeVars|ScopeBody]) -> [?Q("begin _@ScopeVars, [_@ScopeBody] end")] end,
                            ScopeId, AstList, TreeWalker2),
     {{erl_syntax:list(Ast), Info}, TreeWalker3}.
 

+ 6 - 1
tests/src/erlydtl_unittests.erl

@@ -1180,7 +1180,12 @@ tests() ->
                    [{name, [{first,"Bill"},{last,"Buffalo"}]}],
                    [{name, [{first,"Margaret"},{last,"Costanza"}]}],
                    [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
-        <<"Buffalo\nBill\nCondi\nCostanza\nGeorge\nMargaret\n">>}
+        <<"Buffalo\nBill\nCondi\nCostanza\nGeorge\nMargaret\n">>},
+       {"With surrounding context",
+        <<"People: {% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}Done.">>,
+        [{people, [[{first_name, "George"}, {gender, "Male"}], [{first_name, "Bill"}, {gender, "Male"}],
+                   [{first_name, "Margaret"}, {gender, "Female"}], [{first_name, "Condi"}, {gender, "Female"}]]}],
+        <<"People: Male\nGeorge\nBill\nFemale\nMargaret\nCondi\nDone.">>}
       ]},
      {"spaceless", [
                     {"Beginning", <<"{% spaceless %}    <b>foo</b>{% endspaceless %}">>, [], <<"<b>foo</b>">>},