From: noah morrison Date: Tue, 11 Nov 2014 00:48:08 +0000 (-0500) Subject: Added section looping X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=515d1ac5a3bad407c789d3d79f274aae8e141f4b;p=chevron.git Added section looping ( note: not implemented on inverted sections! ) --- diff --git a/entei.py b/entei.py index 2c86ccc..06fcef4 100755 --- 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)