Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test on the lookup-value of translations, not on the whole {trans} va…

…lue. Fixes #362
  • Loading branch information...
commit 0b38011e22f61358bf8a7c0487ac958cb8aac759 1 parent 172f414
@mworrell mworrell authored
View
4 src/erlydtl/erlydtl_compiler.erl
@@ -828,7 +828,7 @@ filter_ast1({filter, {identifier, _, Name}, []}, VariableAst, Context, TreeWalke
filter_ast1({filter, {identifier, _, "default"}, [Arg]}, VariableAst, Context, TreeWalker) ->
{{ArgAst, Info},TreeWalker1} = value_ast(Arg, false, Context, TreeWalker),
VarAst = erl_syntax:variable("Default_" ++ z_ids:identifier()),
- CaseAst = erl_syntax:case_expr(erl_syntax:application(erl_syntax:atom(erlydtl_runtime), erl_syntax:atom(is_false), [VarAst]),
+ CaseAst = erl_syntax:case_expr(erl_syntax:application(erl_syntax:atom(erlydtl_runtime), erl_syntax:atom(is_false), [VarAst, z_context_ast(Context)]),
[erl_syntax:clause([erl_syntax:atom(true)], none,
[ArgAst]),
erl_syntax:clause([erl_syntax:underscore()], none,
@@ -1040,7 +1040,7 @@ ifexpr_ast(Expression, IfContents, ElseChoices, Context, TreeWalker) ->
{{ElseExprAst, ElseExprInfo}, TW1} = value_ast(E, false, Context, TW),
{{erl_syntax:case_expr(erl_syntax:application(erl_syntax:atom(erlydtl_runtime),
erl_syntax:atom(is_false),
- [ElseExprAst]),
+ [ElseExprAst, z_context_ast(Context)]),
[
erl_syntax:clause([erl_syntax:atom(true)], none, [InnerAst]),
erl_syntax:clause([erl_syntax:underscore()], none, [ElseAst])
View
16 src/erlydtl/erlydtl_operators.erl
@@ -42,17 +42,17 @@
]).
-'and'(A, B, _Context) ->
- erlydtl_runtime:is_true(A) and erlydtl_runtime:is_true(B).
+'and'(A, B, Context) ->
+ erlydtl_runtime:is_true(A, Context) and erlydtl_runtime:is_true(B, Context).
-'not'(A, _Context) ->
- not erlydtl_runtime:is_true(A).
+'not'(A, Context) ->
+ erlydtl_runtime:is_false(A, Context).
-'or'(A, B, _Context) ->
- erlydtl_runtime:is_true(A) or erlydtl_runtime:is_true(B).
+'or'(A, B, Context) ->
+ erlydtl_runtime:is_true(A, Context) or erlydtl_runtime:is_true(B, Context).
-'xor'(A, B, _Context) ->
- erlydtl_runtime:is_true(A) xor erlydtl_runtime:is_true(B).
+'xor'(A, B, Context) ->
+ erlydtl_runtime:is_true(A, Context) xor erlydtl_runtime:is_true(B, Context).
add(A, B, _Context) ->
View
11 src/erlydtl/erlydtl_runtime.erl
@@ -164,9 +164,20 @@ fetch_value(Key, Data, Context) ->
are_equal(Arg1, Arg2) ->
z_utils:are_equal(Arg1, Arg2).
+is_false({trans, _} = T, Context) ->
+ z_utils:is_empty(z_trans:lookup_fallback(T, Context));
+is_false(A, _Context) ->
+ is_false(A).
+
is_false(A) ->
not z_convert:to_bool(A).
+
+is_true({trans, _} = T, Context) ->
+ not z_utils:is_empty(z_trans:lookup_fallback(T, Context));
+is_true(A, _Context) ->
+ is_true(A).
+
is_true(A) ->
z_convert:to_bool(A).
View
9 src/tests/erlydtl_unittests.erl
@@ -131,7 +131,13 @@ tests() ->
{"If non-empty string",
<<"{% if var1 %}yay{% endif %}">>, [{var1, "hello"}], <<"yay">>},
{"If proplist",
- <<"{% if var1 %}yay{% endif %}">>, [{var1, [{foo, "bar"}]}], <<"yay">>}
+ <<"{% if var1 %}yay{% endif %}">>, [{var1, [{foo, "bar"}]}], <<"yay">>},
+ {"If non-empty trans",
+ <<"{% if var1 %}yay{% endif %}">>, [{var1, {trans, [{en,<<"x">>}]}}], <<"yay">>},
+ {"If empty trans",
+ <<"{% if var1 %}yay{% endif %}">>, [{var1, {trans, [{en,<<"">>}]}}], <<"">>},
+ {"If not empty trans",
+ <<"{% if not var1 %}yay{% endif %}">>, [{var1, {trans, [{en,<<"">>}]}}], <<"yay">>}
]},
{"for", [
{"Simple loop",
@@ -403,6 +409,7 @@ tests() ->
run_tests() ->
io:format("Running unit tests...~n"),
+ z_trans_server:start_tests(),
Failures = lists:foldl(
fun({Group, Assertions}, GroupAcc) ->
io:format(" Test group ~p...~n", [Group]),
Please sign in to comment.
Something went wrong with that request. Please try again.