[svn] checkpoint
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 cd80053 · Browse files · 5 files·+44 added−15 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+44 added−15 removed
- other:+44 added−15 removed
Provenance
- Commit
c7ddd1d- Tree
41b4248- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
cd80053
5 files changed+44 added−15 removed
modified:docs/src/designerdoc.txt+1 added
609 unmodified lines610 also defines the content that fills the hole in the *parent*. If there were611 two similarly-named ``{% block %}`` tags in a template, that template's612 parent wouldn't know which one of the blocks' content to use.613 614+615 Super Blocks616 ============617 618 Starting with `Jinja 1.1` it's possible to render the contents of the parent474 unmodified linesmodified:jinja/translators/python.py+2 added-4 removed
229 unmodified lines230 #: mapping of unsupported syntax elements.231 #: the value represents the feature name that appears232 #: in the exception.233 self.unsupported = {234- ast.ListComp: 'list comprehensions',235- ast.From: 'imports',236- ast.Import: 'imports',234+ ast.ListComp: 'list comprehensions'235 }236 237 #: because of python2.3 compatibility add generator238 #: expressions only to the list of unused features166 unmodified lines405 # load the template we inherit from and add not known blocks406 parent = self.environment.loader.parse(node.extends.template,407 node.filename)408 # look up all block nodes in the current template and411- # add them to the override dict409+ # add them to the override dict.410 for n in get_nodes(nodes.Block, node):411 overwrites[n.name] = n412 # handle direct overrides413 for n in get_nodes(nodes.Block, parent):829 unmodified linesmodified:jinja/filters.py+13 added-6 removed
120 unmodified lines121 return e(s, attribute)122 return wrapped123 124 125-def do_xmlattr():125+def do_xmlattr(autospace=False):126 """127 Create an SGML/XML attribute string based on the items in a dict.128 All values that are neither `none` nor `undefined` are automatically129 escaped:130 131 .. sourcecode:: html+jinja132 133- <ul {{ {'class': 'my_list', 'missing': None,133+ <ul{{ {'class': 'my_list', 'missing': None,134 'id': 'list-%d'|format(variable)}|xmlattr }}>135 ...136 </ul>137 4 unmodified lines142 <ul class="my_list" id="list-42">143 ...144 </ul>145 146+ As you can see it automatically appends a space in front of the item147+ if the filter returned something. You can disable this by passing148+ `false` as only argument to the filter.149+150 *New in Jinja 1.1*151 """152 e = escape153 def wrapped(env, context, d):5 unmodified lines159 result.append(u'%s="%s"' % (160 e(env.to_unicode(key)),161 e(env.to_unicode(value), True)162 ))159- return u' '.join(result)163+ rv = u' '.join(result)164+ if autospace:165+ rv = ' ' + rv166+ return rv167 return wrapped168 169 170 def do_capitalize(s):150 unmodified lines321 def wrapped(env, context, seq):322 try:323 return iter(seq).next()324 except StopIteration:318- return env.undefined_singleton[0]325+ return env.undefined_singleton326 return wrapped327 328 329 def do_last():3 unmodified lines333 def wrapped(env, context, seq):334 try:335 return iter(_reversed(seq)).next()336 except StopIteration:330- return env.undefined_singleton[-1]337+ return env.undefined_singleton338 return wrapped339 340 341 def do_random():3 unmodified lines345 def wrapped(env, context, seq):346 try:347 return choice(seq)348 except IndexError:342- return env.undefined_singleton[0]349+ return env.undefined_singleton350 return wrapped351 352 353 def do_urlencode():507 unmodified linesmodified:jinja/nodes.py+28 added-4 removed
28 unmodified lines29 node.lineno = offset30 todo.extend(node.getChildNodes())31 32 33-def get_nodes(nodetype, tree):33+def get_nodes(nodetype, tree, exclude_root=True):34 """35- Get all nodes from nodetype in the tree.35+ Get all nodes from nodetype in the tree excluding the36+ node passed if `exclude_root` is `True` (default).37 """38+ if exclude_root:39+ todo = tree.getChildNodes()40+ else:37- todo = [tree]41+ todo = [tree]42 while todo:43 node = todo.pop()44 if node.__class__ is nodetype:45 yield node46 todo.extend(node.getChildNodes())47 48 49+def get_nodes_parentinfo(nodetype, tree):50+ """51+ Like `get_nodes` but it yields tuples in the form ``(parent, node)``.52+ If a node is a direct ancestor of `tree` parent will be `None`.53+54+ Always excludes the root node.55+ """56+ todo = [tree]57+ while todo:58+ node = todo.pop()59+ if node is tree:60+ parent = None61+ else:62+ parent = node63+ for child in node.getChildNodes():64+ if child.__class__ is nodetype:65+ yield parent, child66+ todo.append(child)67+68+69 class Node(ast.Node):70 """71 Jinja node.72 """40 unmodified lines113 return [self.format_string] + list(self.variables)114 115 def __repr__(self):116 return 'DynamicText(%r, %r)' % (93- self.text,117+ self.format_string,118 self.variables119 )120 121 300 unmodified linesmodified:jinja/parser.py-1 removed
529 unmodified lines530 plural = u''.join(plural)531 return nodes.Trans(flineno, singular, plural, indicator,532 replacements or None)533 534-534 def parse_python(self, lineno, gen, template):535 """536 Convert the passed generator into a flat string representing537 python sourcecode and return an ast node or raise a229 unmodified lines