Permalink
Browse files

Merge pull request #1 from interline/nested-child-lists

Support nested list of child elements
  • Loading branch information...
2 parents a11df1c + cff232a commit 730be3d26872d53304de268b88d56307ad6f8e89 @devinus committed Jun 4, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 src/jorge.erl
View
@@ -72,9 +72,18 @@ jorge_list([], Acc) ->
lists:reverse(Acc);
jorge_list([undefined | 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(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).
jorge_test() ->
@@ -98,6 +107,19 @@ jorge_test() ->
{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.

0 comments on commit 730be3d

Please sign in to comment.