Skip to content
Myr

Fixed a bug with the handling of empty statements in macros (it also fixes a bug introduced in one of the previous changesets)

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 4d5bdff · Browse files · 2 files+17 added−7 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+17 added−7 removed

  • other:+17 added−7 removed

2 files+17 added−7 removed

modified:jinja2/compiler.py+15 added-7 removed
136 unmodified lines
137 # conditions. This information is used to optimize inheritance138 # situations.139 self.rootlevel = False140141 # An extends statement flags the frame as silent if it occours.142 # This is used to suppress unwanted output.143 self.silent = False144145 # inside some tags we are using a buffer rather than yield statements.146 # this for example affects {% filter %} or {% macro %}. If a frame147 # is buffered this variable points to the name of the list used as148 # buffer.
257 unmodified lines
406 self.start_write(frame, node)407 self.write(s)408 self.end_write(frame)409406 def blockvisit(self, nodes, frame, force_generator=True):410 def blockvisit(self, nodes, frame):411 """Visit a list of nodes as block in a frame. If the current frame412 is no buffer a dummy ``if 0: yield None`` is written automatically413 unless the force_generator parameter is set to False.414 """411 if frame.buffer is None and force_generator:415 if frame.buffer is None:416 self.writeline('if 0: yield None')417 else:418 self.writeline('pass')419 try:420 for node in nodes:421 self.visit(node, frame)422 except CompilerExit:
333 unmodified lines
756 """Calls the extender."""757 if not frame.toplevel:758 self.fail('cannot use extend from a non top-level scope',759 node.lineno)760 frame.silent = True761762 # if the number of extends statements in general is zero so763 # far, we don't have to add a check if something extended764 # the template before this one.
216 unmodified lines
981 self.writeline('continue')982 self.outdent(2)983984 self.indent()978 self.blockvisit(node.body, loop_frame, force_generator=True)985 self.blockvisit(node.body, loop_frame)986 if node.else_:987 self.writeline('%s = 0' % iteration_indicator)988 self.outdent()989990 if node.else_:991 self.writeline('if %s:' % iteration_indicator)992 self.indent()986 self.blockvisit(node.else_, loop_frame, force_generator=False)993 self.blockvisit(node.else_, loop_frame)994 self.outdent()995996 # reset the aliases if there are any.997 self.restore_shadowed(aliases)
47 unmodified lines
1045 filter_frame.inspect(node.iter_child_nodes())1046 aliases = self.collect_shadowed(filter_frame)1047 self.pull_locals(filter_frame)1048 self.buffer(filter_frame)1042 self.blockvisit(node.body, filter_frame, force_generator=False)1049 self.blockvisit(node.body, filter_frame)1050 self.start_write(frame, node)1051 self.visit_Filter(node.filter, filter_frame)1052 self.end_write(frame)1053 self.restore_shadowed(aliases)
3 unmodified lines
1057 self.visit(node.node, frame)10581059 def visit_Output(self, node, frame):1060 # if we have a known extends statement, we don't output anything1061 # if we are in a silent section1054 if self.has_known_extends and frame.block is None:1062 if self.has_known_extends and frame.silent:1063 return10641065 if self.environment.finalize:1066 finalize = lambda x: unicode(self.environment.finalize(x))
5 unmodified lines
1072 # if we are not in a block and there was already an extends1073 # statement we have to add a check that disables our yield(s) here1074 # so that they don't appear in the output.1075 outdent_later = False1068 if frame.block is None and self.extends_so_far != 0:1076 if frame.silent and self.extends_so_far != 0:1077 self.writeline('if parent_template is None:')1078 self.indent()1079 outdent_later = True1080
347 unmodified lines
modified:CHANGES+2 added
26 unmodified lines
27 area.2829- added `sort` filter that works like `dictsort` but for arbitrary sequences.3031- fixed a bug with empty statements in macros.3233Version 2.034-----------35(codename jinjavitus, released on July 17th 2008)36
32 unmodified lines