[svn] again some updates on the documentation for jinja. this time the debugging stuff
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 2cc3c69 · Browse files · 3 files·+76 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+76 added−4 removed
- other:+76 added−4 removed
Provenance
- Commit
abc0064- Tree
bf55e89- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2cc3c69
3 files changed+76 added−4 removed
added:docs/src/debugging.txt+27 added
1+===================2+Debugging Templates3+===================4+5+In order to keep templates debuggable you have to do some additional work on6+the application side. The traceback module that comes with python currently7+does not support the `__loader__` hook which is used by Jinja to provide8+templates. Although the import system was implemented three Python versions9+ago the default traceback system still doesn't support it.10+11+However most of the extended web development traceback module support it:12+13+- `Colubrid Debugging Middleware`_14+- `cgitb`_15+- `EvalException`_16+17+Note that the django traceback module currently does not provide this. `A18+ticket`_ was filed already so there is hope that this will be fixed.19+20+To enable debugging you have to use one of those debugging systems or21+implement your own one with support for `__loader__`.22+23+24+.. _Colubrid Debugging Middleware: http://trac.pocoo.org/repos/colubrid/trunk/colubrid/debug.py25+.. _cgitb: http://docs.python.org/lib/module-cgitb.html26+.. _EvalException: http://pythonpaste.org/module-paste.evalexception.html27+.. _A ticket: http://code.djangoproject.com/ticket/3734modified:docs/src/designerdoc.txt+47 added
281 unmodified lines282 using an infix notation too: ``foo is not bar`` and ``foo not in bar``283 instead of ``not foo is bar`` and ``not foo in bar``. All other expressions284 require a prefix notation: ``not (foo and bar)``.285 286+Boolean Values287+==============288+289+In If-Conditions Jinja performs a boolean check. All empty values (eg: empty290+lists ``[]``, empty dicts ``{}`` etc) evaluate to `false`. Numbers that are291+equal to `0`/`0.00` are considered `false` too. The boolean value of other292+objects depends on the behavior the application developer gave it. Usually293+items are `true`.294+295+Here some examples that should explain it:296+297+.. sourcecode:: jinja298+299+ {% if [] %}300+ will always be false because it's an empty list301+302+ {% if {} %}303+ false too.304+305+ {% if ['foo'] %}306+ this is true. Because the list is not empty.307+308+ {% if "foobar" %}309+ this is also true because the string is not empty.310+311+Slicing312+=======313+314+Some objects support slicing operations. For example lists:315+316+.. sourcecode:: jinja317+318+ {% for item in items[:5] %}319+ This will only iterate over the first 5 items of the list320+321+ {% for item in items[5:10] %}322+ This will only iterate from item 5 to 10.323+324+ {% for item in items[:10:2] %}325+ This will only yield items from start to ten and only returing326+ even items.327+328+For more informations about slicing have a look at the `slicing chapter`_329+in the "Dive into Python" e-book.330+331 Macros332 ======333 334 If you want to use a partial template in more than one place, you might want to301 unmodified lines636 {{ count }} users found.637 {% else %}638 one user found.639 {% endif %}640+641+.. _slicing chapter: http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slicemodified:docs/src/index.txt+2 added-4 removed
22 unmodified lines23 - `Translators <translators.txt>`_24 25 - `Framework Integration <frameworks.txt>`_26 27+ - `Debugging Support <debugging.txt>`_28+29 - Template Designer Documentation:30 31 - `Syntax Reference <designerdoc.txt>`_32 12 unmodified lines45 46 - Jinja in TurboGears / django?47 48 - Changelog / Authors47-48-- Boolean Rules (empty lists evaluate to False etc)49-50-- Slicing