Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make dictsort use deep find

  • Loading branch information...
commit 9d3da509fc49caadabdfb9f07455eba826bff47e 1 parent e157b4d
@garazdawi garazdawi authored garazdawi committed
Showing with 14 additions and 3 deletions.
  1. +14 −3 src/erlydtl_filters.erl
View
17 src/erlydtl_filters.erl
@@ -218,10 +218,21 @@ default_if_none(undefined, Default) ->
default_if_none(Input, _) ->
Input.
-%% @doc Takes a list of dictionaries and returns that list sorted by the key given in the argument.
+%% @doc Takes a list of dictionaries or proplists and returns that list sorted by the key given in the argument.
+dictsort(DictList, Key) when is_binary(Key) ->
+ dictsort(DictList, [binary_to_atom(B,latin1) ||
+ B <- binary:split(Key,<<".">>)]);
dictsort(DictList, Key) ->
- case lists:all(fun(Dict) -> dict:is_key(Key, Dict) end, DictList) of
- true -> lists:sort(fun(K1,K2) -> dict:find(Key,K1) =< dict:find(Key,K2) end, DictList);
+ case lists:all(
+ fun(Dict) ->
+ erlydtl_runtime:find_deep_value(Key, Dict) /= undefined
+ end, DictList) of
+ true ->
+ lists:sort(
+ fun(K1,K2) ->
+ erlydtl_runtime:find_deep_value(Key,K1) =<
+ erlydtl_runtime:find_deep_value(Key,K2)
+ end, DictList);
false -> error
end.
Please sign in to comment.
Something went wrong with that request. Please try again.