- inclusions and imports "with context" forward all variables now, not only
the initial context.
-- added a cycle helper called `cycle`.
+- added a cycle helper called `cycler`.
+
+- added a joining helper called `joiner`.
Version 2.0
-----------
**new in Jinja 2.1**
+.. class:: joiner(sep=', ')
+
+ A tiny helper that can be use to "join" multiple sections. A joiner is
+ passed a string and will return that string every time it's calld, except
+ the first time in which situation it returns an empty string. You can
+ use this to join things::
+
+ {% set pipe = joiner("|") %}
+ {% if categories %} {{ pipe() }}
+ Categories: {{ categories|join(", ") }}
+ {% endif %}
+ {% if author %} {{ pipe() }}
+ Author: {{ author() }}
+ {% endif %}
+ {% if can_edit %} {{ pipe() }}
+ <a href="?action=edit">Edit</a>
+ {% endif %}
+
+ **new in Jinja 2.1**
+
Extensions
----------
:copyright: 2007-2008 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
-from jinja2.utils import generate_lorem_ipsum, Cycler
+from jinja2.utils import generate_lorem_ipsum, Cycler, Joiner
# defaults for the parser / lexer
'range': xrange,
'dict': lambda **kw: kw,
'lipsum': generate_lorem_ipsum,
- 'cycler': Cycler
+ 'cycler': Cycler,
+ 'joiner': Joiner
}
contents = f.read().decode(self.encoding)
finally:
f.close()
- old = path.getmtime(filename)
- return contents, filename, lambda: path.getmtime(filename) == old
+
+ mtime = path.getmtime(filename)
+ def uptodate():
+ try:
+ return path.getmtime(filename) == mtime
+ except OSError:
+ return False
+ return contents, filename, uptodate
raise TemplateNotFound(template)
filename = self.provider.get_resource_filename(self.manager, p)
mtime = path.getmtime(filename)
def uptodate():
- return path.getmtime(filename) == mtime
+ try:
+ return path.getmtime(filename) == mtime
+ except OSError:
+ return False
source = self.provider.get_resource_string(self.manager, p)
return source.decode(self.encoding), filename, uptodate
return rv
+class Joiner(object):
+ """A joining helper for templates."""
+
+ def __init__(self, sep=u', '):
+ self.sep = sep
+ self.used = False
+
+ def __call__(self):
+ if not self.used:
+ self.used = True
+ return u''
+ return self.sep
+
+
# we have to import it down here as the speedups module imports the
# markup type which is define above.
try: