Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Rename "plus" to "add" to conform to standard DTL.

* Throw error for undefined variable in the "for" tag.
  • Loading branch information...
commit 156312970ceca168ab7c00339d054b337b3b51d0 1 parent b33692d
@evanmiller evanmiller authored
View
2  src/erlydtl/erlydtl_compiler.erl
@@ -577,7 +577,7 @@ for_loop_ast(IteratorList, Variable, Contents, Context, TreeWalker) ->
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]);
View
18 src/erlydtl/erlydtl_filters.erl
@@ -43,6 +43,15 @@
(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 ->
@@ -142,15 +151,6 @@ rjust(Input, Number) when is_binary(Input) ->
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) ->
View
6 src/tests/erlydtl_unittests.erl
@@ -177,6 +177,9 @@ tests() ->
{"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">>},
@@ -224,9 +227,6 @@ tests() ->
{"|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.">>},
Please sign in to comment.
Something went wrong with that request. Please try again.