Skip to content
Myr

fixed include

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent f059ec1 · Browse files · 3 files+24 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+24 added−11 removed

  • other:+24 added−11 removed

3 files+24 added−11 removed

modified:jinja2/parser.py+7 added-4 removed
159 unmodified lines
160 node = nodes.Include(lineno=self.stream.expect('include').lineno)161 expr = self.parse_expression()162 if self.stream.current.type is 'assign':163 self.stream.next()164 node.target = self.stream.expect('name')165 # make sure that assignments to that name are allowed166 if not nodes.Name(node.target, 'store').can_assign():164 if not isinstance(expr, nodes.Name):165 raise TemplateSyntaxError('must assign imported template to '166 'variable or current scope',167 expr.lineno, self.filename)168 if not expr.can_assign():169 raise TemplateSyntaxError('can\'t assign imported template '168 'to %r' % node.target, expr.lineno,170 'to %r' % expr, expr.lineno,171 self.filename)172 node.target = expr.name173 node.template = self.parse_expression()174 else:175 node.target = None176 node.template = expr
487 unmodified lines
modified:jinja2/runtime.py+13 added-4 removed
94 unmodified lines
95class IncludedTemplate(object):96 """Represents an included template."""9798 def __init__(self, environment, context, template):99 root = environment.get_template(template).root_render_func100 gen = root(context, standalone=True)101 self._context = gen.next().get_exported()99 template = environment.get_template(template)100 gen = template.root_render_func(context, standalone=True)101 context = gen.next()102 self._filename = template.name103 self._rendered_body = u''.join(gen)104 self._context = context.get_exported()105106 def __getitem__(self, name):107 return self._context[name]108109 def __unicode__(self):110 return self._context111112 def __repr__(self):113 return '<%s %r>' % (114 self.__class__.__name__,115 self._filename116 )117118119class LoopContextBase(object):120 """Helper for extended iteration."""121122 def __init__(self, iterable, parent=None):
114 unmodified lines
237238 def fail(self, *args, **kwargs):239 raise TypeError(self._undefined_hint)240 __getattr__ = __getitem__ = __add__ = __mul__ = __div__ = \233 __realdiv__ = __floordiv__ = __mod__ = __pos__ = __neg__ = fail241 __realdiv__ = __floordiv__ = __mod__ = __pos__ = __neg__ = \242 __call__ = fail243 del fail244245 def __unicode__(self):246 return ''
10 unmodified lines
modified:test.py+4 added-3 removed
2 unmodified lines
34env = Environment(loader=DictLoader({5'child.html': u'''\6{% extends master_layout or 'master.html' %}7{% include 'helpers.html' %}7{% include helpers = 'helpers.html' %}8{% macro get_the_answer() %}42{% endmacro %}9{% title = 'Hello World' %}10{% block body %}11 {{ get_the_answer() }}11 {{ conspirate() }}12 {{ helpers.conspirate() }}13{% endblock %}14''',15'master.html': u'''\16<!doctype html>16<title>Foo</title>17<title>{{ title }}</title>18{% block body %}{% endblock %}19''',20'helpers.html': u'''\21{% macro conspirate() %}23{% endmacro %}
6 unmodified lines