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
Provenance
- Commit
f40c884- Tree
37d1008- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
4d5bdff
2 files changed+17 added−7 removed
modified:jinja2/compiler.py+15 added-7 removed
136 unmodified lines137 # conditions. This information is used to optimize inheritance138 # situations.139 self.rootlevel = False140 141+ # An extends statement flags the frame as silent if it occours.142+ # This is used to suppress unwanted output.143+ self.silent = False144+145 # 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 lines406 self.start_write(frame, node)407 self.write(s)408 self.end_write(frame)409 406- 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 lines756 """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 = True761 762 # 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 lines981 self.writeline('continue')982 self.outdent(2)983 984 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()989 990 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()995 996 # reset the aliases if there are any.997 self.restore_shadowed(aliases)47 unmodified lines1045 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 lines1057 self.visit(node.node, frame)1058 1059 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 return1064 1065 if self.environment.finalize:1066 finalize = lambda x: unicode(self.environment.finalize(x))5 unmodified lines1072 # 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 linesmodified:CHANGES+2 added
26 unmodified lines27 area.28 29 - added `sort` filter that works like `dictsort` but for arbitrary sequences.30 31+- fixed a bug with empty statements in macros.32+33 Version 2.034 -----------35 (codename jinjavitus, released on July 17th 2008)36 32 unmodified lines