From: Armin Ronacher Date: Sat, 14 Apr 2007 22:56:32 +0000 (+0200) Subject: [svn] documented debug.foobar and added it to the CHANGES X-Git-Tag: 2.0rc1~356 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=90a5cb3eb9311b2d7011e1fe8bea201d19313902;p=jinja2.git [svn] documented debug.foobar and added it to the CHANGES --HG-- branch : trunk --- diff --git a/CHANGES b/CHANGES index 18b727a..2d34821 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Version 1.1 - debugging system improved, smaller filesize for the cached files. Debugging works now well for any module using linecache. +- ``{{ debug() }}`` can now be used to get a list of filters and + tags. + - added whitespace management system for the template designer. - some small bugfixes. diff --git a/docs/src/designerdoc.txt b/docs/src/designerdoc.txt index 05db1d0..2f5dcc7 100644 --- a/docs/src/designerdoc.txt +++ b/docs/src/designerdoc.txt @@ -132,6 +132,20 @@ These tests are especially useful when used in `if` conditions. [[list_of_tests]] +*new in Jinja 1.1*: + +Because the application can provide additional tests you can get a documentation +of all the provided tests by calling ``debug.tests()``: + +.. sourcecode:: jinja + + {{ debug.tests() }} + -> returns a plain text representation of all the tests + + {{ debug.tests(False) }} + -> same as above but without the builtin ones. + + Global Functions ================ diff --git a/jinja/utils.py b/jinja/utils.py index 33afac7..c233945 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -400,6 +400,24 @@ class DebugHelper(object): return '\n\n'.join(result) filters.jinja_context_callable = True + def tests(self, env, context, builtins=True): + """List the tests.""" + from inspect import getdoc + strip = set() + if not builtins: + from jinja.defaults import DEFAULT_TESTS + strip = set(DEFAULT_TESTS.values()) + tests = env.tests.items() + tests.sort(lambda a, b: cmp(a[0].lower(), b[0].lower())) + result = [] + for name, f in tests: + if f in strip: + continue + doc = '\n'.join(' ' + x for x in (getdoc(f) or '').splitlines()) + result.append('`%s`\n\n%s' % (name, doc)) + return '\n\n'.join(result) + tests.jinja_context_callable = True + def __str__(self): print 'use debug() for debugging the context'