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)
insides = [] replacer = ''
for item in context[section_name]: if it and not hasattr(it, '__iter__'):
ctx = context.copy() replacer = inner
ctx.update(item) elif it:
insides.append(self.render(inner, ctx)) insides = []
template = template.replace(section, ''.join(insides)) for item in context[section_name]:
else: ctx = context.copy()
template = template.replace(section, inner) ctx.update(item)
else: insides.append(self.render(inner, ctx))
template = template.replace(section, '') replacer = ''.join(insides)
template = template.replace(section, replacer)
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