Skip to content
Myr

some documentation changes

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 39e7476 · Browse files · 11 files+65 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+65 added−26 removed

  • other:+65 added−26 removed

11 files+65 added−26 removed

modified:docs/src/designerdoc.txt+26 added-2 removed
65 unmodified lines
66 {{ users[current_user].username }}67 If you have numerical indices you have to use the [] syntax:68 {{ users[0].username }}6970*new in Jinja 1.2*: You can now use django like attributes for integer71indices. Thus ``{{ foo.0 }}`` is equivalent to ``{{ foo[0] }}``.727374Loops75=====7677To iterate over a sequence, you can use the `for` loop. It basically looks like a
160 unmodified lines
238 ``{{ 1 / 2 }}`` would return ``0.5``.239 ``//`` divide the left operand by the right one and return a truncated240 integer result: ``{{ 20 // 7 }}`` is ``2``.241 *added in Jinja 1.1*242 ``~`` string concatenate a value with another one. ``{{ foo ~ bar }}``243 is equivalent to ``{{ foo|string + bar|string }}``. *added in244 Jinja 1.1*245 ``*`` multiply the left operand with the right one.246 ``{{ 2 * 2 }}`` would return ``4``.247 ``**`` raise the left operand to the power of the right248 operand. ``{{ 2**3 }}`` would return ``8``.
18 unmodified lines
267 using an infix notation too: ``foo is not bar`` and ``foo not in bar``268 instead of ``not foo is bar`` and ``not foo in bar``. All other expressions269 require a prefix notation: ``not (foo and bar)``.270271272With Jinja 1.2 onwards it's possible to replace basic if/else blocks with the273inline `if` / `else` expression. The following two examples evaluate to the274same:275276.. source:: jinja277278 {{ "something" if expr else "otherthing" }}279280 {% if expr %}something{% else %}otherthing{% endif %}281282283Boolean Values284==============285286In If-Conditions Jinja performs a boolean check. All empty values (eg: empty
107 unmodified lines
394395For information regarding the visibility of macros have a look at the396`Scopes and Variable Behavior`_ section.397398399Extended Macro Call400===================401402*new in Jinja 1.1*
81 unmodified lines
484*new in Jinja 1.1* you can now render an included template to a string that is485evaluated in an indepdendent environment by calling `rendertemplate`. See the486documentation for this function in the `builtins`_ documentation.487488489Filtering Blocks490================491492Sometimes it could be a good idea to filter a complete block of text. For
16 unmodified lines
509 {% endfilter %}510511returns ``"<b>some text</b>"``.512513514Defining Variables515==================516517You can also define variables in the namespace using the ``{% set %}`` tag:
7 unmodified lines
525526For information regarding the visibility of variables have a look at the527`Scopes and Variable Behavior`_ section.528529530Reserved Keywords531=================532533Jinja has some keywords you cannot use a variable names. This limitation511exists to make look coherent. Syntax highlighters won't mess things up and512you will don't have unexpected output.534exists to make templates look coherent. Syntax highlighters won't mess things535up and you won't have the situation that some names work depending on the536context.537538The following keywords exist and cannot be used as identifiers:539540 `and`, `block`, `cycle`, `elif`, `else`, `endblock`, `endfilter`,
17 unmodified lines
modified:docs/src/devrecipies.txt+1 added
2 unmodified lines
3=======================45Here some recipies for application developers.678Automagic Template Variables9============================1011Python allows some magic stack manipulation which can be used to
116 unmodified lines
modified:docs/src/inheritance.txt+7 added-1 removed
67 unmodified lines
68 {% endblock %}6970The ``{% extends %}`` tag is the key here. It tells the template engine that71this template "extends" another template. When the template system evaluates72this template, first it locates the parent.72this template, first it locates the parent. It must be always the first tag73in a template but whitespace or a comment is allowed before. This was not74enforced with Jinja 1.0 and 1.1, it does however raise a syntax error with751.2 or later.7677The filename of the template depends on the template loader. For example the78``FileSystemLoader`` allows you to access other templates by giving the79filename. You can access templates in subdirectories with an slash:
15 unmodified lines
95 also defines the content that fills the hole in the *parent*. If there were96 two similarly-named ``{% block %}`` tags in a template, that template's97 parent wouldn't know which one of the blocks' content to use.9899100How Inheritance Works Internally101================================102103Inheritance in Jinja is straightforward. If a template contains an
37 unmodified lines
141 This can work although it probably makes no sense in this specific case.142 However the condition is handled at runtime because it's in a valid block143 and defines a new block subtemplates can override.144145146Super Blocks147============148149Starting with `Jinja 1.1` it's possible to render the contents of the parent
10 unmodified lines
160161 {{ super(2) }}162 return the data of the second parent block163164165Block Shortcuts166===============167168With Jinja 1.1 onwards it's possible to have a shortcut syntax for blocks
10 unmodified lines
modified:docs/src/installation.txt+3 added-3 removed
34 unmodified lines
3536If you want to play around with the code37----------------------------------------38391. Install `Subversion`_402. ``svn co http://trac.pocoo.org/repos/jinja/trunk jinja``391. Install `mercurial`_402. ``svn co http://dev.pocoo.org/hg/jinja-main jinja``413. ``cd jinja``424. ``ln -s jinja /usr/lib/python2.X/site-packages``4344As an alternative to steps 4 you can also do ``python setup.py develop``
24 unmodified lines
6970.. _download page: http://jinja.pocoo.org/download.html71.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools72.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall73.. _Subversion: http://subversion.tigris.org/73.. _mercurial: http://www.selenic.com/mercurial/
modified:docs/src/loaders.txt+1 added
147 unmodified lines
148149.. _memcached: http://www.danga.com/memcached/150.. _python-memcached: http://www.tummy.com/Community/software/python-memcached/151152153How Mixin Classes Work154======================155156The idea of the cached loader mixins is that you override the `load`
89 unmodified lines
modified:docs/src/objects.txt+1 added
3 unmodified lines
45This section covers the behavior of global objects in the Jinja namespace and6also the behavior of their attributes.789Functions10=========1112`Filters`_ and `Tests`_ are special kind of functions you cannot call without
142 unmodified lines
modified:docs/src/scopes.txt+3 added
3 unmodified lines
45This section of the documentation covers the Jinja behavior regarding6variable visibility.789Scopes10======1112Jinja has multiple scopes. A scope is something like a new transparent foil on
17 unmodified lines
30Defined macros appear on the context as variables. Because of this, they are31affected by the scoping too. A macro defined inside of a macro is just available32in those two macros (the macro itself and the macro it's defined in).333435Template Globals36================3738A special threatment exists for template code outside of visible blocks in
68 unmodified lines
107 were not top-level were not propagated to the layout template. This made108 it impossible to use conditional expressions for inclusion in non root109 templates.110111112Undefined Variables113===================114115If you have already worked with python you probably know about the fact that
72 unmodified lines
modified:jinja/loaders.py+4 added-2 removed
264 unmodified lines
265class MemcachedLoaderMixin(object):266 """267 Uses a memcached server to cache the templates.268269 Requires the memcache library from tummy__.269 Requires the memcache library from `tummy`_ or the cmemcache library270 from `Gijsbert de Haan`_.271272 With Jinja 1.2 onwards you can also provide a `client` keyword argument273 that takes an already instanciated memcache client or memcache client274 like object.275275 __ http://www.tummy.com/Community/software/python-memcached/276 .. _tummy: http://www.tummy.com/Community/software/python-memcached/277 .. _Gisjsbert de Haan: http://gijsbert.org/cmemcache/278 """279280 def __init__(self, use_memcache, memcache_time=60 * 60 * 24 * 7,281 memcache_host=None, item_prefix='template/', client=None):
493 unmodified lines
modified:CHANGES+1 added-1 removed
71 unmodified lines
72- if the set that is postfixed with a bang (!) it acts like the python 373 "nonlocal" keyword. This means that you can now override variables74 defined in the outer scope from within a loop.7576- ``foo + bar`` is now a simpler alternative to ``foo|string + bar|string``76- ``foo ~ bar`` is now a simpler alternative to ``foo|string + bar|string``7778- `PackageLoader` can now work without pkg_resources too7980- added `getattribute` and `getitem` filter.
130 unmodified lines
modified:MANIFEST.in+2 added-1 removed
1include docs/build/*.html1include Makefile CHANGES LICENSE AUTHORS TODO ez_setup.py2include docs/build/*.html3include docs/src/*.txt4recursive-include tests *
modified:setup.py+16 added-16 removed
51 unmodified lines
52 print '=' * 79535455setup(56 name = 'Jinja',57 version = '1.2',58 url = 'http://jinja.pocoo.org/',59 license = 'BSD',60 author = 'Armin Ronacher',61 author_email = 'armin.ronacher@active-4.com',62 description = 'A small but fast and easy to use stand-alone template '63 'engine written in pure python.',56 name='Jinja',57 version='1.2',58 url='http://jinja.pocoo.org/',59 license='BSD',60 author='Armin Ronacher',61 author_email='armin.ronacher@active-4.com',62 description='A small but fast and easy to use stand-alone template '63 'engine written in pure python.',64 long_description = getdoc(jinja),65 # jinja is egg safe. But because we distribute the documentation66 # in form of html and txt files it's a better idea to extract the files67 zip_safe = False,68 classifiers = [67 zip_safe=False,68 classifiers=[69 'Development Status :: 5 - Production/Stable',70 'Environment :: Web Environment',71 'Intended Audience :: Developers',72 'License :: OSI Approved :: BSD License',
2 unmodified lines
75 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',76 'Topic :: Software Development :: Libraries :: Python Modules',77 'Topic :: Text Processing :: Markup :: HTML'78 ],79 keywords = ['python.templating.engines'],80 packages = ['jinja', 'jinja.translators'],81 data_files = [79 keywords=['python.templating.engines'],80 packages=['jinja', 'jinja.translators'],81 data_files=[82 ('docs', list(list_files('docs/build'))),83 ('docs/txt', list(list_files('docs/src')))84 ],85 entry_points='''86 [python.templating.engines]87 jinja = jinja.plugin:BuffetPlugin88 ''',89 extras_require = {'plugin': ['setuptools>=0.6a2']},90 features = {89 extras_require={'plugin': ['setuptools>=0.6a2']},90 features={91 'speedups': Feature(92 'optional C-speed enhancements',93 standard = True,94 ext_modules = [
7 unmodified lines
102 Extension('jinja._debugger', ['jinja/_debugger.c'])103 ]104 )105 },106 cmdclass = {'build_ext': optional_build_ext}106 cmdclass={'build_ext': optional_build_ext}107)