Skip to content
Myr

Implemented and documented "joiner"

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 ccae055 · Browse files · 5 files+52 added−6 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+52 added−6 removed

  • other:+52 added−6 removed

5 files+52 added−6 removed

modified:docs/templates.rst+20 added
1078 unmodified lines
1079 Returns the current item.1080 1081 **new in Jinja 2.1**10821083.. class:: joiner(sep=', ')10841085 A tiny helper that can be use to "join" multiple sections. A joiner is1086 passed a string and will return that string every time it's calld, except1087 the first time in which situation it returns an empty string. You can1088 use this to join things::10891090 {% set pipe = joiner("|") %}1091 {% if categories %} {{ pipe() }}1092 Categories: {{ categories|join(", ") }}1093 {% endif %}1094 {% if author %} {{ pipe() }}1095 Author: {{ author() }}1096 {% endif %}1097 {% if can_edit %} {{ pipe() }}1098 <a href="?action=edit">Edit</a>1099 {% endif %}11001101 **new in Jinja 2.1**110211031104Extensions1105----------11061107The following sections cover the built-in Jinja2 extensions that may be
96 unmodified lines
modified:jinja2/defaults.py+3 added-2 removed
6 unmodified lines
78 :copyright: 2007-2008 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from jinja2.utils import generate_lorem_ipsum, Cycler11from jinja2.utils import generate_lorem_ipsum, Cycler, Joiner121314# defaults for the parser / lexer15BLOCK_START_STRING = '{%'
13 unmodified lines
29DEFAULT_NAMESPACE = {30 'range': xrange,31 'dict': lambda **kw: kw,32 'lipsum': generate_lorem_ipsum,33 'cycler': Cycler33 'cycler': Cycler,34 'joiner': Joiner35}363738# export all constants
1 unmodified line
modified:jinja2/loaders.py+12 added-3 removed
147 unmodified lines
148 try:149 contents = f.read().decode(self.encoding)150 finally:151 f.close()152 old = path.getmtime(filename)153 return contents, filename, lambda: path.getmtime(filename) == old152153 mtime = path.getmtime(filename)154 def uptodate():155 try:156 return path.getmtime(filename) == mtime157 except OSError:158 return False159 return contents, filename, uptodate160 raise TemplateNotFound(template)161162163class PackageLoader(BaseLoader):
32 unmodified lines
196 if self.filesystem_bound:197 filename = self.provider.get_resource_filename(self.manager, p)198 mtime = path.getmtime(filename)199 def uptodate():200 try:194 return path.getmtime(filename) == mtime201 return path.getmtime(filename) == mtime202 except OSError:203 return False204205 source = self.provider.get_resource_string(self.manager, p)206 return source.decode(self.encoding), filename, uptodate207
102 unmodified lines
modified:jinja2/utils.py+14 added
683 unmodified lines
684 self.pos = (self.pos + 1) % len(self.items)685 return rv686687688class Joiner(object):689 """A joining helper for templates."""690691 def __init__(self, sep=u', '):692 self.sep = sep693 self.used = False694695 def __call__(self):696 if not self.used:697 self.used = True698 return u''699 return self.sep700701702# we have to import it down here as the speedups module imports the703# markup type which is define above.704try:705 from jinja2._speedups import escape, soft_unicode
37 unmodified lines
modified:CHANGES+3 added-1 removed
35 unmodified lines
3637- inclusions and imports "with context" forward all variables now, not only38 the initial context.3940- added a cycle helper called `cycle`.40- added a cycle helper called `cycler`.4142- added a joining helper called `joiner`.4344Version 2.045-----------46(codename jinjavitus, released on July 17th 2008)47
32 unmodified lines