From 515d1ac5a3bad407c789d3d79f274aae8e141f4b Mon Sep 17 00:00:00 2001 From: noah morrison Date: Mon, 10 Nov 2014 19:48:08 -0500 Subject: [PATCH] Added section looping ( note: not implemented on inverted sections! ) --- entei.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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) -- 2.47.3