Skip to content
Myr

Unified some code in the super/template reference system.

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 1b54f74 · Browse files · 5 files+45 added−16 removed
This commit

State

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

Diff stats

5 files+45 added−16 removed

  • other:+45 added−16 removed

5 files+45 added−16 removed

modified:docs/templates.rst+3 added-1 removed
344 unmodified lines
345 <title>{% block title %}{% endblock %}</title>346 <h1>{{ self.title() }}</h1>347 {% block body %}{% endblock %}348349349Unlike Python Jinja does not support multiple inheritance. So you can only have350one extends tag called per rendering.351352
260 unmodified lines
613`caller`614 This is `true` if the macro accesses the special `caller` variable and may615 be called from a :ref:`call<call>` tag.616617If a macro name starts with an underscore it's not exported and can't618be imported.619620621.. _call:622623Call624~~~~
504 unmodified lines
modified:examples/rwbench/rwbench.py+3 added-1 removed
76 unmodified lines
77 mako_template.render_unicode(**context)787980from djangoext import django_loader, DjangoContext81django_template = django_loader.get_template('index.html')81def test_django():82 # not cached because django is not thread safe and does83 # not cache by itself so it would be unfair to cache it here.84 django_template = django_loader.get_template('index.html')85 django_template.render(DjangoContext(context))868788def test_genshi():
11 unmodified lines
modified:examples/bench.py+6 added-3 removed
59 unmodified lines
60 from django.template import Template as DjangoTemplate, Context as DjangoContext61except ImportError:62 test_django = None63else:64 django_template = DjangoTemplate("""\64 django_template = """\65<!doctype html>66<html>67 <head>68 <title>{{ page_title }}</title>
19 unmodified lines
88 </table>89 </div>90 </body>91</html>\92""")92"""9394 def test_django():95 c = DjangoContext(context)96 c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'),97 ('products.html', 'Products')]98 django_template.render(c)98 # recompile template each rendering because that's what django99 # is doing in normal situations too. Django is not thread safe100 # so we can't cache it in regular apps either.101 DjangoTemplate(django_template).render(c)102103try:104 from mako.template import Template as MakoTemplate105except ImportError:
214 unmodified lines
modified:ext/django2jinja/django2jinja.py+1 added-1 removed
411 unmodified lines
412413414@node(loader_tags.BlockNode)415def block(writer, node):416 writer.tag('block ' + node.name.replace('-', '_'))416 writer.tag('block ' + node.name.replace('-', '_').rstrip('_'))417 node = node418 while node.parent is not None:419 node = node.parent420 writer.body(node.nodelist)
262 unmodified lines
modified:jinja2/runtime.py+32 added-10 removed
77 unmodified lines
78 def super(self, name, current):79 """Render a parent block."""80 try:81 blocks = self.blocks[name]82 block = blocks[blocks.index(current) + 1]82 index = blocks.index(current) + 183 blocks[index]84 except LookupError:85 return self.environment.undefined('there is no parent block '86 'called %r.' % name,87 name='super')87 wrap = self.environment.autoescape and Markup or (lambda x: x)88 render = lambda: wrap(concat(block(self)))89 render.__name__ = render.name = name90 return render88 return BlockReference(name, self, blocks, index)8990 def get(self, key, default=None):91 """Returns an item from the template context, if it doesn't exist92 `default` is returned.
86 unmodified lines
179 def __init__(self, context):180 self.__context = context181182 def __getitem__(self, name):185 func = self.__context.blocks[name][0]183 blocks = self.__context.blocks[name]184 wrap = self.__context.environment.autoescape and \185 Markup or (lambda x: x)188 render = lambda: wrap(concat(func(self.__context)))189 render.__name__ = render.name = name190 return render186 return BlockReference(name, self.__context, blocks, 0)187188 def __repr__(self):189 return '<%s %r>' % (190 self.__class__.__name__,195 self._context.name191 self.__context.name192 )193194195class BlockReference(object):196 """One block on a template reference."""197198 def __init__(self, name, context, stack, depth):199 self.name = name200 self._context = context201 self._stack = stack202 self._depth = depth203204 @property205 def super(self):206 """Super the block."""207 if self._depth + 1 >= len(self._stack):208 return self._context.environment. \209 undefined('there is no parent block called %r.' %210 self.name, name='super')211 return BlockReference(self.name, self._context, self._stack,212 self._depth + 1)213214 def __call__(self):215 rv = concat(self._stack[self._depth](self._context))216 if self._context.environment.autoescape:217 rv = Markup(rv)218 return rv219220221class LoopContext(object):222 """A loop context for dynamic iteration."""223224 def __init__(self, iterable, recurse=None):
259 unmodified lines