Commit dbb50631 by Eric Florenzano

Flattened the render_sections loop

parent 8303869d
...@@ -29,18 +29,20 @@ class Template(object): ...@@ -29,18 +29,20 @@ class Template(object):
break break
section, section_name, inner = match.group(0, 1, 2) section, section_name, inner = match.group(0, 1, 2)
if section_name in context and context[section_name]:
if hasattr(context[section_name], '__iter__'): it = context.get(section_name)
replacer = ''
if it and not hasattr(it, '__iter__'):
replacer = inner
elif it:
insides = [] insides = []
for item in context[section_name]: for item in context[section_name]:
ctx = context.copy() ctx = context.copy()
ctx.update(item) ctx.update(item)
insides.append(self.render(inner, ctx)) insides.append(self.render(inner, ctx))
template = template.replace(section, ''.join(insides)) replacer = ''.join(insides)
else:
template = template.replace(section, inner) template = template.replace(section, replacer)
else:
template = template.replace(section, '')
return template return template
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment