Sorry, the code sample was overly complicated. Here is a simpler
version.
---------------------------------------
from jinja2 import Template, Environment, BaseLoader,
environmentfilter
@environmentfilter
def render_child(env, child):
return child.render(env)
class Loader(BaseLoader):
def get_source(self, env, className):
cls = globals()[className]
templSrc = cls.__dict__['template']
return templSrc, className, lambda: True
class NodeBase(object):
def render(self, env):
print type(env)
className = self.__class__.__name__
template = env.get_template(className)
return template.render(this=self)
class NodeTypeB(NodeBase):
template = 'BBBBBBBB'
class NodeTypeC(NodeBase):
template = 'CCCCCCC'
class NodeTypeA(NodeBase):
template = '''
AAAAAAAAA
{% for c in this.children %}
{{ c | render_child() }}
{% endfor %}
AAAAAAAAA
'''
def __init__(self):
self.children = [NodeTypeB(), NodeTypeC()]
env = Environment(loader=Loader())
env.filters['render_child'] = render_child
n = NodeTypeA()
print n.render(env)
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.