added with-statement extension.
--HG--
branch : trunk
diff --git a/jinja2/ext.py b/jinja2/ext.py
index 482ca6c..c3c8eec 100644
--- a/jinja2/ext.py
+++ b/jinja2/ext.py
@@ -336,6 +336,27 @@
return nodes.Continue(lineno=token.lineno)
+class WithExtension(Extension):
+ """Adds support for a django-like with block."""
+ tags = set(['with'])
+
+ def parse(self, parser):
+ node = nodes.Scope(lineno=next(parser.stream).lineno)
+ assignments = []
+ while parser.stream.current.type != 'block_end':
+ lineno = parser.stream.current.lineno
+ if assignments:
+ parser.stream.expect('comma')
+ target = parser.parse_assign_target()
+ parser.stream.expect('assign')
+ expr = parser.parse_expression()
+ assignments.append(nodes.Assign(target, expr, lineno=lineno))
+ node.body = assignments + \
+ list(parser.parse_statements(('name:endwith',),
+ drop_needle=True))
+ return node
+
+
def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS,
babel_style=True):
"""Extract localizable strings from the given template node. Per
@@ -507,3 +528,4 @@
i18n = InternationalizationExtension
do = ExprStmtExtension
loopcontrols = LoopControlExtension
+with_ = WithExtension