Commit dbb50631 by Eric Florenzano

Flattened the render_sections loop

parent 8303869d
......@@ -29,18 +29,20 @@ class Template(object):
break
section, section_name, inner = match.group(0, 1, 2)
if section_name in context and context[section_name]:
if hasattr(context[section_name], '__iter__'):
insides = []
for item in context[section_name]:
ctx = context.copy()
ctx.update(item)
insides.append(self.render(inner, ctx))
template = template.replace(section, ''.join(insides))
else:
template = template.replace(section, inner)
else:
template = template.replace(section, '')
it = context.get(section_name)
replacer = ''
if it and not hasattr(it, '__iter__'):
replacer = inner
elif it:
insides = []
for item in context[section_name]:
ctx = context.copy()
ctx.update(item)
insides.append(self.render(inner, ctx))
replacer = ''.join(insides)
template = template.replace(section, replacer)
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