--- /dev/null
+from jinja import Environment as E1
+from jinja2 import Environment as E2
+from mako.template import Template as M
+
+t1, t2 = [e.from_string("""
+<ul>
+{%- for item in seq %}
+ <li>{{ item|e }}</li>
+{%- endfor %}
+</ul>
+""") for e in E1(), E2()]
+
+m = M("""
+<ul>
+% for item in seq:
+ <li>${item|h}</li>
+% endfor
+</ul>
+""")
self.identifiers.undeclared.add(node.name)
def visit_Filter(self, node):
+ self.generic_visit(node)
if node.name not in self.identifiers.filters:
self.identifiers.filters.add(node.name)
return u''.join(self.stream(*args, **kwargs))
def stream(self, *args, **kwargs):
- context = dict(*args, **kwargs)
- return self.root_render_func(context)
+ return self.root_render_func(dict(*args, **kwargs))
"""HTML escape an object."""
if hasattr(obj, '__html__'):
return obj.__html__()
- s = unicode(obj) \
+ return unicode(obj) \
.replace('&', '&') \
.replace('>', '>') \
- .replace('<', '<')
- if attribute:
- s = s.replace('"', '"')
- return s
+ .replace('<', '<') \
+ .replace('"', '"')
-from jinja import Environment as E1
-from jinja2 import Environment as E2
+from jinja2 import Environment
-t1, t2 = [e.from_string("""
-<ul>
-{%- for item in seq %}
- <li>{{ item|e }}</li>
-{%- endfor %}
-</ul>
-""") for e in E1(), E2()]
+env = Environment()
+tmpl = env.from_string("""<!doctype html>
+<html>
+ <head>
+ <title>{{ page_title|e }}</title>
+ </head>
+ <body>
+ <ul class="navigation">
+ {%- for href, caption in [
+ ('index.html', 'Index'),
+ ('projects.html', 'Projects'),
+ ('about.html', 'About')
+ ] %}
+ <li><a href="{{ href|e }}">{{ caption|e }}</a></li>
+ {%- endfor %}
+ </ul>
+ <div class="body">
+ {{ body }}
+ </div>
+ </body>
+</html>\
+""")
+
+
+print tmpl.render(page_title='<foo>', body='<p>Hello World</p>')