Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Support nested list of child elements
  • Loading branch information...
commit 730be3d26872d53304de268b88d56307ad6f8e89 2 parents a11df1c + cff232a
Devin Torres authored

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. 22  src/jorge.erl
22  src/jorge.erl
@@ -72,9 +72,18 @@ jorge_list([], Acc) ->
72 72
     lists:reverse(Acc);
73 73
 jorge_list([undefined | Rest], Acc) ->
74 74
     jorge_list(Rest, Acc);
  75
+jorge_list([List | Rest], Acc) when is_list(List) ->
  76
+    jorge_nested_list(List, Rest, Acc);
75 77
 jorge_list([Head | Rest], Acc) ->
76 78
     jorge_list(Rest, [jorge_node(Head) | Acc]).
77 79
 
  80
+jorge_nested_list([], Siblings, Acc) ->
  81
+    jorge_list(Siblings, Acc);
  82
+jorge_nested_list([undefined | Rest], Siblings, Acc) ->
  83
+    jorge_nested_list(Rest, Siblings, Acc);
  84
+jorge_nested_list([Head | Rest], Siblings, Acc) ->
  85
+    jorge_nested_list(Rest, Siblings, [jorge_node(Head) | Acc]).
  86
+
78 87
 -ifdef(TEST).
79 88
 
80 89
 jorge_test() ->
@@ -98,6 +107,19 @@ jorge_test() ->
98 107
                 {spam, fun() -> eggs end}
99 108
             ]}
100 109
         }
  110
+    ),
  111
+    
  112
+    Nested = [<<"<nested>">>,
  113
+                [[<<"<foo>">>, <<"bar">>, <<"</foo>">>],
  114
+                 [<<"<abc>">>, <<"123">>, <<"</abc>">>],
  115
+                 [<<"<def>">>, <<"456">>, <<"</def>">>]],
  116
+              <<"</nested>">>],
  117
+    
  118
+    Nested = jorge(
  119
+        {nested, [
  120
+            {foo, bar},
  121
+            [{abc, 123}, undefined, {def, 456}]
  122
+        ]}
101 123
     ).
102 124
 
103 125
 -endif.

0 notes on commit 730be3d

Please sign in to comment.
Something went wrong with that request. Please try again.