`IncludedTemplate` uses getattr rather then getitem now
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 963f97d · Browse files · 2 files·+16 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+16 added−8 removed
- other:+16 added−8 removed
Provenance
- Commit
6ce170c- Tree
350223d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
963f97d
2 files changed+16 added−8 removed
modified:jinja2/compiler.py+1 added-1 removed
791 unmodified lines792 self.write(')')793 794 def visit_ExprStmt(self, node, frame):795 self.newline(node)796- self.visit(node, frame)796+ self.visit(node.node, frame)797 798 def visit_Output(self, node, frame):799 # if we have a known extends statement, we don't output anything800 if self.has_known_extends and frame.toplevel:275 unmodified linesmodified:jinja2/environment.py+15 added-7 removed
13 unmodified lines14 from jinja2.optimizer import optimize15 from jinja2.compiler import generate16 from jinja2.runtime import Undefined, TemplateContext17 from jinja2.debug import translate_exception18-from jinja2.utils import import_string, LRUCache18+from jinja2.utils import import_string, LRUCache, Markup19 from jinja2.defaults import DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE20 21 22 # for direct template usage we have up to ten living environments324 unmodified lines347 return TemplateContext(self.environment, dict(self.globals, **vars),348 self.name, self.blocks)349 350 def include(self, context=None):351- """Include this template."""351+ """Include this template. When passed a template context or dict352+ the template is evaluated in that context and an `IncludedTemplate`353+ object is returned. This object then exposes all the exported354+ variables as attributes and renders the contents of the template355+ when converted to unicode.356+ """357 if context is None:358 context = self.new_context({})359 elif isinstance(context, TemplateContext):360 context = self.new_context(context.get_root())33 unmodified lines394 class IncludedTemplate(object):395 """Represents an included template."""396 397 def __init__(self, template, context):393- self._template = template398+ body = Markup(u''.join(template.root_render_func(context)))399+ self.__dict__.update(context.get_exported())400 self._name = template.name395- self._rendered_body = u''.join(template.root_render_func(context))396- self._context = context.get_exported()401+ self._rendered_body = body402 398- __getitem__ = lambda x, n: x._context[n]399- __html__ = __unicode__ = lambda x: x._rendered_body403+ __html__ = lambda x: x._rendered_body404+ __unicode__ = lambda x: unicode(x._rendered_body)405 406+ def __str__(self):407+ return unicode(self._rendered_body).encode('utf-8')408+409 def __repr__(self):410 return '<%s %r>' % (411 self.__class__.__name__,412 self._name55 unmodified lines