]> Devi Nivas Git - chevron.git/commitdiff
Added section looping
authornoah morrison <noah@morrison.ph>
Tue, 11 Nov 2014 00:48:08 +0000 (19:48 -0500)
committernoah morrison <noah@morrison.ph>
Tue, 11 Nov 2014 02:13:00 +0000 (21:13 -0500)
( note: not implemented on inverted sections! )

entei.py

index 2c86ccc2faa35dad1c1249fcc9e296926d8e15f9..06fcef41681dc9e2055142ef356d6ce998a8f675 100755 (executable)
--- a/entei.py
+++ b/entei.py
@@ -206,7 +206,10 @@ def render(template, data, partials_path='.', partials_ext='mustache',
             except IOError:
                 return StringIO(None)
 
-    tokens = tokenize(template)
+    if type(template) is list:
+        tokens = template
+    else:
+        tokens = tokenize(template)
 
     output = ''
     if type(data) is list:
@@ -237,7 +240,21 @@ def render(template, data, partials_path='.', partials_ext='mustache',
 
         elif tag == 'section':
             scope = get_key(key)
-            scopes.insert(0, scope)
+
+            if type(scope) is list:
+                tags = []
+                for tag in tokens:
+                    if tag == ('end', key):
+                        break
+                    tags.append(tag)
+
+                for thing in scope:
+                    new_scope = [thing] + scopes
+                    output += render(tags, new_scope, partials_path,
+                                     partials_ext, partials_dict)
+
+            else:
+                scopes.insert(0, scope)
 
         elif tag == 'inverted section':
             scope = get_key(key)