Permalink
Browse files

Merge commit 'svnmirror/master' into ejango

  • Loading branch information...
2 parents c07aa50 + bb48da2 commit f300b210e94f0f58341a4aea8c944dc10b6c4828 @archaelus archaelus committed Jan 23, 2009
Showing with 36 additions and 9 deletions.
  1. +3 −3 src/erlydtl/erlydtl_compiler.erl
  2. +7 −0 src/erlydtl/erlydtl_filters.erl
  3. +26 −6 src/tests/erlydtl_unittests.erl
@@ -536,11 +536,11 @@ resolve_scoped_variable_ast(VarName, Context) ->
end, undefined, Context#dtl_context.local_scopes).
format(Ast, Context) ->
- auto_escape(format_integer_ast(Ast), Context).
+ auto_escape(format_number_ast(Ast), Context).
-format_integer_ast(Ast) ->
- erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(format_integer),
+format_number_ast(Ast) ->
+ erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(format_number),
[Ast]).
@@ -112,6 +112,13 @@ format_integer(Input) when is_integer(Input) ->
format_integer(Input) ->
Input.
+format_number(Input) when is_integer(Input) ->
+ integer_to_list(Input);
+format_number(Input) when is_float(Input) ->
+ io_lib:format("~p", [Input]);
+format_number(Input) ->
+ Input.
+
join([Input], Separator) when is_list(Input) ->
string:join(Input, Separator).
@@ -4,13 +4,24 @@
tests() ->
[
+ {"vars", [
+ {"string",
+ <<"String value is: {{ var1 }}">>,
+ [{var1, "foo"}], <<"String value is: foo">>},
+ {"int",
+ <<"The magic number is: {{ var1 }}">>,
+ [{var1, 42}], <<"The magic number is: 42">>},
+ {"float",
+ <<"The price of milk is: {{ var1 }}">>,
+ [{var1, 0.42}], <<"The price of milk is: 0.42">>}
+ ]},
{"comment", [
- {"Comment block is excised",
- <<"Bob {% comment %}(moron){% endcomment %} Loblaw">>,
- [], <<"Bob Loblaw">>},
- {"Inline comment is excised",
- <<"You're {# not #} a very nice person">>,
- [], <<"You're a very nice person">>}
+ {"comment block is excised",
+ <<"bob {% comment %}(moron){% endcomment %} loblaw">>,
+ [], <<"bob loblaw">>},
+ {"inline comment is excised",
+ <<"you're {# not #} a very nice person">>,
+ [], <<"you're a very nice person">>}
]},
{"autoescape", [
{"Autoescape works",
@@ -235,6 +246,15 @@ tests() ->
<<"Ben &amp; Jerry&#039;s &lt;=&gt; &quot;The World&#039;s Best Ice Cream&quot;">>},
{"|format_integer",
<<"{{ var1|format_integer }}">>, [{var1, 28}], <<"28">>},
+ {"|format_number 1",
+ <<"{{ var1|format_number }}">>, [{var1, 28}], <<"28">>},
+ {"|format_number 2",
+ <<"{{ var1|format_number }}">>, [{var1, 23.77}], <<"23.77">>},
+ {"|format_number 3",
+ <<"{{ var1|format_number }}">>, [{var1, "28.77"}], <<"28.77">>},
+ {"|format_number 4",
+ <<"{{ var1|format_number }}">>, [{var1, "23.77"}], <<"23.77">>},
+
{"|join:\", \"",
<<"{{ var1|join:\", \" }}">>, [{var1, ["Liberte", "Egalite", "Fraternite"]}],
<<"Liberte, Egalite, Fraternite">>},

0 comments on commit f300b21

Please sign in to comment.