Skip to content

Commit

Permalink
Merge pull request #1 from interline/nested-child-lists
Browse files Browse the repository at this point in the history
Support nested list of child elements
  • Loading branch information
Devin Torres committed Jun 4, 2012
2 parents a11df1c + cff232a commit 730be3d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/jorge.erl
Expand Up @@ -72,9 +72,18 @@ jorge_list([], Acc) ->
lists:reverse(Acc); lists:reverse(Acc);
jorge_list([undefined | Rest], Acc) -> jorge_list([undefined | Rest], Acc) ->
jorge_list(Rest, Acc); jorge_list(Rest, Acc);
jorge_list([List | Rest], Acc) when is_list(List) ->
jorge_nested_list(List, Rest, Acc);
jorge_list([Head | Rest], Acc) -> jorge_list([Head | Rest], Acc) ->
jorge_list(Rest, [jorge_node(Head) | Acc]). jorge_list(Rest, [jorge_node(Head) | Acc]).


jorge_nested_list([], Siblings, Acc) ->
jorge_list(Siblings, Acc);
jorge_nested_list([undefined | Rest], Siblings, Acc) ->
jorge_nested_list(Rest, Siblings, Acc);
jorge_nested_list([Head | Rest], Siblings, Acc) ->
jorge_nested_list(Rest, Siblings, [jorge_node(Head) | Acc]).

-ifdef(TEST). -ifdef(TEST).


jorge_test() -> jorge_test() ->
Expand All @@ -98,6 +107,19 @@ jorge_test() ->
{spam, fun() -> eggs end} {spam, fun() -> eggs end}
]} ]}
} }
),

Nested = [<<"<nested>">>,
[[<<"<foo>">>, <<"bar">>, <<"</foo>">>],
[<<"<abc>">>, <<"123">>, <<"</abc>">>],
[<<"<def>">>, <<"456">>, <<"</def>">>]],
<<"</nested>">>],

Nested = jorge(
{nested, [
{foo, bar},
[{abc, 123}, undefined, {def, 456}]
]}
). ).


-endif. -endif.

0 comments on commit 730be3d

Please sign in to comment.