Commits

Anonymous committed 73816a6

1. "|join" processes iodata()
2. atoms can be compared to lists in "ifequal" clause

Thanks to indogus, insane, and kiszl for bug reports and patches.

Comments (0)

Files changed (3)

src/erlydtl/erlydtl_filters.erl

     Input.
 
 join([Input], Separator) when is_list(Input) ->
-    string:join(Input, Separator).
+    join_io(Input, Separator).
 
 last([Input]) when is_list(Input) or is_binary(Input) ->
     last(Input);
 fix_ampersands([C | Rest], Acc) ->
     fix_ampersands(Rest, [C | Acc]).
 
+join_io([], _Sep) -> [];
+join_io([_] = X, _Sep) -> X;
+join_io([X|T], Sep) -> [X,Sep] ++ join_io(T, Sep).
+
 linebreaksbr(Input, Index) when is_binary(Input) ->
     Break = <<"<br />">>,
     case Input of

src/erlydtl/erlydtl_runtime.erl

     are_equal(Arg1, Arg2);
 are_equal(Arg1, [Arg2]) when is_list(Arg1) ->
     are_equal(Arg1, Arg2);
+are_equal(Arg1, Arg2) when is_atom(Arg1), is_list(Arg2) ->
+	 are_equal(atom_to_list(Arg1), Arg2);
+are_equal(Arg1, Arg2) when is_list(Arg1), is_atom(Arg2) ->
+	 are_equal(Arg1, atom_to_list(Arg2));
 are_equal(_, _) ->
     false.
 

src/tests/erlydtl_unittests.erl

                     [{var1, 2}], <<"yay">>},
                 {"Compare variable to unequal literal (int)",
                     <<"{% ifequal var1 2 %}boo{% else %}yay{% endifequal %}">>,
-                    [{var1, 3}], <<"yay">>}
+                    [{var1, 3}], <<"yay">>},
+                {"Compare variable to equal literal (atom)",
+                    <<"{% ifequal var1 \"foo\"%}yay{% endifequal %}">>,
+                    [{var1, foo}], <<"yay">>},
+                {"Compare variable to unequal literal (atom)",
+                    <<"{% ifequal var1 \"foo\"%}yay{% else %}boo{% endifequal %}">>,
+                    [{var1, bar}], <<"boo">>}
             ]},
         {"ifequal/else", [
                 {"Compare variable to literal",
                     <<"{{ var1|format_number }}">>, [{var1, fun() -> 29 end}], <<"29">>},
                 {"|format_number 6",
                     <<"{{ var1|format_number }}">>, [{var1, fun() -> fun() -> 31 end end}], <<"31">>},
- 
-                {"|join:\", \"",
+                {"|join:\", \" (list)",
                     <<"{{ var1|join:\", \" }}">>, [{var1, ["Liberte", "Egalite", "Fraternite"]}],
                     <<"Liberte, Egalite, Fraternite">>},
+                {"|join:\", \" (binary)",
+                    <<"{{ var1|join:\", \" }}">>, [{var1, [<<"Liberte">>, "Egalite", <<"Fraternite">>]}],
+                    <<"Liberte, Egalite, Fraternite">>},
                 {"|last",
                     <<"{{ var1|last }}">>, [{var1, "XYZ"}],
                     <<"Z">>},