Skip to content
Myr

[svn] requirements (macros and set directives) can be outside of renderable blocks too

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 7c3be90 · Browse files · 4 files+39 added−5 removed
This commit

State

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

Diff stats

4 files+39 added−5 removed

  • tests:+9 added−1 removed
  • other:+30 added−4 removed

4 files+39 added−5 removed

modified:jinja/translators/python.py+29 added-2 removed
207 unmodified lines
208 # if there is a parent template we parse the parent template and209 # update the blocks there. Once this is done we drop the current210 # template in favor of the new one. Do that until we found the211 # root template.212 requirements_todo = []213 while node.extends is not None:214 if node not in requirements_todo:215 requirements_todo.append(node)216217 tmpl = self.environment.loader.parse(node.extends.template,218 node.filename)219 # handle block inheritance220 for block in tmpl.blocks.itervalues():221 if block.name in node.blocks:222 block.replace(node.blocks[block.name])223 node = tmpl224225 if tmpl not in requirements_todo:226 requirements_todo.append(node)227228 # look up requirements229 requirements = []230 for req in requirements_todo:231 for n in req:232 if n.__class__ in (nodes.Set, nodes.Macro):233 requirements.append(n)234235 # bootstrapping code236 lines = [237 'from __future__ import division\n'238 'from jinja.datastructure import Undefined, LoopContext, CycleContext\n\n'239 'def generate(context, write):\n'240 ' # BOOTSTRAPPING CODE\n'241 ' environment = context.environment\n'242 ' get_attribute = environment.get_attribute\n'243 ' perform_test = environment.perform_test\n'244 ' apply_filters = environment.apply_filters\n'
1 unmodified line
246 ' call_function_simple = environment.call_function_simple\n'247 ' finish_var = environment.finish_var'248 ]249 self.indention = 1250251 # we have requirements? add them here.252 if requirements:253 lines.append(self.indent('# REQUIREMENTS'))254 for n in requirements:255 lines.append(self.handle_node(n))256 lines.append(self.indent('# END OF REQUIREMENTS'))257258 # the template body259 rv = self.handle_node_list(node)260261 # add translation helpers if required262 if self.require_translations:263 lines.append(264 ' translator = context.get_translator()\n'265 ' def translate(s, p=None, n=None, r=None):\n'
193 unmodified lines
459 else.460 """461 rv = self.handle_node(node.body)462 if not rv:436 return self.indent('# EMPTY BLOCK (%r:%s)' % (463 return self.indent('# EMPTY BLOCK FROM %r, LINE %s' % (464 node.filename or '?',465 node.lineno466 ))467468 buf = []469 write = lambda x: buf.append(self.indent(x))470444 write('# BLOCK (%r:%s)' % (471 write('# BLOCK FROM %r, LINE %s' % (472 node.filename or '?',473 node.lineno474 ))475 write('context.push()')
317 unmodified lines
modified:jinja/parser.py+1 added-1 removed
155 unmodified lines
156 raise ValueError()157 except (StopIteration, ValueError):158 raise TemplateSyntaxError('invalid syntax for set', lineno)159 ast = self.parse_python(lineno, gen, '(%s)')160 return nodes.Set(lineno, name[2], ast.expr)160 return nodes.Set(lineno, str(name[2]), ast.expr)161162 def handle_filter_directive(self, lineno, gen):163 """164 Handle {% filter foo|bar %} directives.
316 unmodified lines
modified:jinja/utils.py-1 removed
34 unmodified lines
35 return Markup(_escape_res[not attribute].sub(lambda m:36 _escape_pairs[m.group()], unicode(x)))37383939def find_translations(environment, source):40 """41 Find all translatable strings in a template and yield42 them as (lineno, singular, plural) tuples. If a plural
8 unmodified lines
modified:tests/templates/index.html+9 added-1 removed