Commits

emmi...@a5195066-8e3e-0410-a82a-05b01b1b9875  committed 6046c26

* Rename "plus" to "add" to conform to standard DTL.
* Throw error for undefined variable in the "for" tag.

  • Participants
  • Parent commits c85f320

Comments (0)

Files changed (3)

File src/erlydtl/erlydtl_compiler.erl

                     end, IteratorList)] | Context#dtl_context.local_scopes]}, TreeWalker),
     CounterAst = erl_syntax:application(erl_syntax:atom(erlydtl_runtime), 
         erl_syntax:atom(increment_counter_stats), [erl_syntax:variable("Counters")]),
-    {ListAst, VarName} = resolve_ifvariable_ast(Variable, Context),
+    {ListAst, VarName} = resolve_variable_ast(Variable, Context),
     CounterVars0 = case resolve_scoped_variable_ast("forloop", Context) of
         undefined ->
             erl_syntax:application(erl_syntax:atom(erlydtl_runtime), erl_syntax:atom(init_counter_stats), [ListAst]);

File src/erlydtl/erlydtl_filters.erl

                                   (C =:= $\. orelse C =:= $- 
                                   orelse C =:= $~ orelse C =:= $_))).
 
+add([Input], Number) when is_list(Input) or is_binary(Input) ->
+    add(Input, Number);
+add(Input, Number) when is_binary(Input) ->
+    list_to_binary(add(binary_to_list(Input), Number));
+add(Input, Number) when is_list(Input) ->
+    integer_to_list(add(list_to_integer(Input), Number));
+add(Input, Number) when is_integer(Input) ->
+    Input + Number.
+
 capfirst([Input]) when is_list(Input) or is_binary (Input) ->
     capfirst(Input);
 capfirst([H|T]) when H >= $a andalso H =< $z ->
 rjust(Input, Number) ->
     string:right(Input, Number).
 
-plus([Input], Number) when is_list(Input) or is_binary(Input) ->
-    plus(Input, Number);
-plus(Input, Number) when is_binary(Input) ->
-    list_to_binary(plus(binary_to_list(Input), Number));
-plus(Input, Number) when is_list(Input) ->
-    integer_to_list(plus(list_to_integer(Input), Number));
-plus(Input, Number) when is_integer(Input) ->
-    Input + Number.
-
 upper([Input]) when is_list(Input) or is_binary(Input) ->
     upper(Input);
 upper(Input) when is_binary(Input) ->

File src/tests/erlydtl_unittests.erl

                 {"Escape is applied last",
                     <<"{{ var1|escape|linebreaksbr }}">>, [{var1, <<"\n">>}],
                     <<"&lt;br /&gt;">>},
+                {"|add:4",
+                    <<"{{ one|add:4 }}">>, [{one, "1"}],
+                    <<"5">>},
                 {"|capfirst",
                     <<"{{ var1|capfirst }}">>, [{var1, "dana boyd"}], 
                     <<"Dana boyd">>},
                 {"|rjust:10",
                     <<"{{ var1|rjust:10 }}">>, [{var1, "Bush"}],
                     <<"      Bush">>},
-                {"|plus:4",
-                    <<"{{ one|plus:4 }}">>, [{one, "1"}],
-                    <<"5">>},
                 {"|upper",
                     <<"{{ message|upper }}">>, [{message, "That man has a gun."}],
                     <<"THAT MAN HAS A GUN.">>},