[svn] added many new tests to jinja
--HG--
branch : trunk
diff --git a/docs/generate.py b/docs/generate.py
index 8acf5b7..f8e8238 100755
--- a/docs/generate.py
+++ b/docs/generate.py
@@ -260,7 +260,7 @@
def handle_file(filename, fp, dst, preproc):
now = datetime.now()
title = os.path.basename(filename)[:-4]
- content = fp.read()
+ content = fp.read().decode('utf-8')
suffix = not preproc and '.html' or ''
parts = generate_documentation(content, (lambda x: './%s%s' % (x, suffix)))
result = file(os.path.join(dst, title + '.html'), 'w')
diff --git a/docs/src/altsyntax.txt b/docs/src/altsyntax.txt
index 088445c..9fb3b64 100644
--- a/docs/src/altsyntax.txt
+++ b/docs/src/altsyntax.txt
@@ -46,7 +46,7 @@
<ul>
<% for item in seq %>
<li><%= item %></li>
- <% endfor %>
+ <% endâ€for %>
</ul>
@@ -82,7 +82,7 @@
Block / Variable Tag Unification
---------------------------------
+================================
If variable end and start tags are `None` or look the same as block tags and
you're running Jinja 1.1 or later the parser will switch into the
@@ -103,3 +103,6 @@
{else}
Something is {something}.
{endif}
+
+This feature however can cause strange looking templates because there is no
+visible difference between blocks and variables.
diff --git a/docs/src/designerdoc.txt b/docs/src/designerdoc.txt
index ba5de71..d48dde2 100644
--- a/docs/src/designerdoc.txt
+++ b/docs/src/designerdoc.txt
@@ -419,7 +419,11 @@
`and`, `block`, `cycle`, `elif`, `else`, `endblock`, `endfilter`,
`endfor`, `endif`, `endmacro`, `endraw`, `endtrans`, `extends`, `filter`,
`for`, `if`, `in`, `include`, `is`, `macro`, `not`, `or`, `pluralize`,
- `print`, `raw`, `recursive`, `set`, `trans`
+ `print`, `raw`, `recursive`, `set`, `trans`, `call`*, `endcall`*,
+
+keywords marked with `*` can be used until Jinja 1.3 as identifiers because
+they were introduced after the Jinja 1.0 release and can cause backwards
+compatiblity problems otherwise. You should not use them any more.
If you want to use such a name you have to prefix or suffix it or use
alternative names:
@@ -430,11 +434,6 @@
{{ macro_('foo') }}
{% endfor %}
-If future Jinja releases add new keywords those will be "light" keywords which
-means that they won't raise an error for several releases but yield warnings
-on the application side. But it's very unlikely that new keywords will be
-added.
-
Bleeding Edge
=============
diff --git a/docs/src/devrecipies.txt b/docs/src/devrecipies.txt
index ae70226..7f5b6c0 100644
--- a/docs/src/devrecipies.txt
+++ b/docs/src/devrecipies.txt
@@ -23,16 +23,17 @@
class AutoEnvironment(Environment):
- def autorender(self):
- return self.render(sys._getframe(1).f_locals)
+ def autorender(self, template):
+ tmpl = self.get_template(template)
+ return tmpl.render(sys._getframe(1).f_locals)
You can use it now like this:
.. sourcecode:: python
- foo_tmpl = env.get_template('foo.html')
-
def foo():
seq = range(10)
foo = "blub"
- return foo_tmpl.autorender()
+ return env.autorender('foo.html')
+
+In the template you can now access the local variables `seq` and `foo`.
diff --git a/docs/src/objects.txt b/docs/src/objects.txt
index b1f86e4..7b0641f 100644
--- a/docs/src/objects.txt
+++ b/docs/src/objects.txt
@@ -49,6 +49,30 @@
template. Of course you can modify the context too. For more informations about
the context object have a look at the `context object`_ documentation.
+The new ``{% call %}`` tag that exists with Jinja 1.1 onwards can not only
+be used with Jinja macros but also with Python functions. If a template
+designers uses the ``{% call %}`` tag to call a function provided by the
+application Jinja will call this function with a keyword argument called
+`caller` which points to a `function`. If you call this function (optionally
+with keyword arguments that appear in the context) you get a string back
+that was the content of that block. This should explain this:
+
+.. sourcecode:: python
+
+ def make_dialog(title, caller=None):
+ body = ''
+ if caller:
+ body = caller(title=title)
+ return '<div class="dialog"><h2>%s</h2>%s</div>' % (title, body)
+
+This can be used like this in the template now:
+
+.. sourcecode:: html+jinja
+
+ {% call make_dialog('Dialog Title') %}
+ This is the body of the dialog entitled "{{ title }}".
+ {% endcall %}
+
Deferred Values
===============