Skip to content

Commit

Permalink
Merge pull request #239 from irccloud/tuple_wrapped_proplists
Browse files Browse the repository at this point in the history
Support tuple wrapped list keyfind lookups
  • Loading branch information
kaos committed Apr 9, 2016
2 parents aecc1e7 + 0d7e0a1 commit 7633fb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/erlydtl_runtime.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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} ->
Expand Down
2 changes: 2 additions & 0 deletions test/erlydtl_test_defs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,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",
Expand Down

0 comments on commit 7633fb9

Please sign in to comment.