Browse Source

Support tuple wrapped list keyfind lookups

This is useful for data decoded from JSON or prepared for encoding to JSON with jiffy.
James Wheare 9 years ago
parent
commit
0d7e0a1fb3
2 changed files with 4 additions and 0 deletions
  1. 2 0
      src/erlydtl_runtime.erl
  2. 2 0
      test/erlydtl_test_defs.erl

+ 2 - 0
src/erlydtl_runtime.erl

@@ -81,6 +81,8 @@ find_value(Key, {GBSize, GBData}) when is_integer(GBSize) ->
     end;
 find_value(Key, Tuple) when is_tuple(Tuple) ->
     case element(1, Tuple) of
+        L when is_list(L) andalso size(Tuple) =:= 1 ->
+            find_value(Key, L);
         dict ->
             case dict:find(Key, Tuple) of
                 {ok, Val} ->

+ 2 - 0
test/erlydtl_test_defs.erl

@@ -132,6 +132,8 @@ all_test_defs() ->
         <<"I also enjoy {{ var1.game }}">>, [{var1, [{"game", "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
        {"Render variable with binary-key attribute",
         <<"I also enjoy {{ var1.game }}">>, [{var1, [{<<"game">>, "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
+       {"Render variable with tuple wrapped proplist",
+        <<"I also enjoy {{ var1.game }}">>, [{var1, {[{<<"game">>, "Parcheesi"}]}}], <<"I also enjoy Parcheesi">>},
        {"Render variable in dict",
         <<"{{ var1 }}">>, dict:store(var1, "bar", dict:new()), <<"bar">>},
        {"Render variable with missing attribute in dict",