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
Provenance
- Commit
015b0c9- Tree
2f83952- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
39e7476
11 files changed+65 added−26 removed
modified:docs/src/designerdoc.txt+26 added-2 removed
65 unmodified lines66 {{ users[current_user].username }}67 If you have numerical indices you have to use the [] syntax:68 {{ users[0].username }}69 70+*new in Jinja 1.2*: You can now use django like attributes for integer71+indices. Thus ``{{ foo.0 }}`` is equivalent to ``{{ foo[0] }}``.72+73+74 Loops75 =====76 77 To iterate over a sequence, you can use the `for` loop. It basically looks like a160 unmodified lines238 ``{{ 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 lines267 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)``.270 271+272+With Jinja 1.2 onwards it's possible to replace basic if/else blocks with the273+inline `if` / `else` expression. The following two examples evaluate to the274+same:275+276+.. source:: jinja277+278+ {{ "something" if expr else "otherthing" }}279+280+ {% if expr %}something{% else %}otherthing{% endif %}281+282+283 Boolean Values284 ==============285 286 In If-Conditions Jinja performs a boolean check. All empty values (eg: empty107 unmodified lines394 395 For information regarding the visibility of macros have a look at the396 `Scopes and Variable Behavior`_ section.397 398+399 Extended Macro Call400 ===================401 402 *new in Jinja 1.1*81 unmodified lines484 *new in Jinja 1.1* you can now render an included template to a string that is485 evaluated in an indepdendent environment by calling `rendertemplate`. See the486 documentation for this function in the `builtins`_ documentation.487 488+489 Filtering Blocks490 ================491 492 Sometimes it could be a good idea to filter a complete block of text. For16 unmodified lines509 {% endfilter %}510 511 returns ``"<b>some text</b>"``.512 513+514 Defining Variables515 ==================516 517 You can also define variables in the namespace using the ``{% set %}`` tag:7 unmodified lines525 526 For information regarding the visibility of variables have a look at the527 `Scopes and Variable Behavior`_ section.528 529+530 Reserved Keywords531 =================532 533 Jinja has some keywords you cannot use a variable names. This limitation511-exists to make look coherent. Syntax highlighters won't mess things up and512-you will don't have unexpected output.534+exists to make templates look coherent. Syntax highlighters won't mess things535+up and you won't have the situation that some names work depending on the536+context.537 538 The following keywords exist and cannot be used as identifiers:539 540 `and`, `block`, `cycle`, `elif`, `else`, `endblock`, `endfilter`,17 unmodified linesmodified:docs/src/devrecipies.txt+1 added
2 unmodified lines3 =======================4 5 Here some recipies for application developers.6 7+8 Automagic Template Variables9 ============================10 11 Python allows some magic stack manipulation which can be used to116 unmodified linesmodified:docs/src/inheritance.txt+7 added-1 removed
67 unmodified lines68 {% endblock %}69 70 The ``{% extends %}`` tag is the key here. It tells the template engine that71 this template "extends" another template. When the template system evaluates72-this template, first it locates the parent.72+this template, first it locates the parent. It must be always the first tag73+in a template but whitespace or a comment is allowed before. This was not74+enforced with Jinja 1.0 and 1.1, it does however raise a syntax error with75+1.2 or later.76 77 The filename of the template depends on the template loader. For example the78 ``FileSystemLoader`` allows you to access other templates by giving the79 filename. You can access templates in subdirectories with an slash:15 unmodified lines95 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.98 99+100 How Inheritance Works Internally101 ================================102 103 Inheritance in Jinja is straightforward. If a template contains an37 unmodified lines141 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.144 145+146 Super Blocks147 ============148 149 Starting with `Jinja 1.1` it's possible to render the contents of the parent10 unmodified lines160 161 {{ super(2) }}162 return the data of the second parent block163 164+165 Block Shortcuts166 ===============167 168 With Jinja 1.1 onwards it's possible to have a shortcut syntax for blocks10 unmodified linesmodified:docs/src/installation.txt+3 added-3 removed
34 unmodified lines35 36 If you want to play around with the code37 ----------------------------------------38 39-1. Install `Subversion`_40-2. ``svn co http://trac.pocoo.org/repos/jinja/trunk jinja``39+1. Install `mercurial`_40+2. ``svn co http://dev.pocoo.org/hg/jinja-main jinja``41 3. ``cd jinja``42 4. ``ln -s jinja /usr/lib/python2.X/site-packages``43 44 As an alternative to steps 4 you can also do ``python setup.py develop``24 unmodified lines69 70 .. _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 lines148 149 .. _memcached: http://www.danga.com/memcached/150 .. _python-memcached: http://www.tummy.com/Community/software/python-memcached/151 152+153 How Mixin Classes Work154 ======================155 156 The idea of the cached loader mixins is that you override the `load`89 unmodified linesmodified:docs/src/objects.txt+1 added
3 unmodified lines4 5 This section covers the behavior of global objects in the Jinja namespace and6 also the behavior of their attributes.7 8+9 Functions10 =========11 12 `Filters`_ and `Tests`_ are special kind of functions you cannot call without142 unmodified linesmodified:docs/src/scopes.txt+3 added
3 unmodified lines4 5 This section of the documentation covers the Jinja behavior regarding6 variable visibility.7 8+9 Scopes10 ======11 12 Jinja has multiple scopes. A scope is something like a new transparent foil on17 unmodified lines30 Defined macros appear on the context as variables. Because of this, they are31 affected by the scoping too. A macro defined inside of a macro is just available32 in those two macros (the macro itself and the macro it's defined in).33 34+35 Template Globals36 ================37 38 A special threatment exists for template code outside of visible blocks in68 unmodified lines107 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.110 111+112 Undefined Variables113 ===================114 115 If you have already worked with python you probably know about the fact that72 unmodified linesmodified:jinja/loaders.py+4 added-2 removed
264 unmodified lines265 class MemcachedLoaderMixin(object):266 """267 Uses a memcached server to cache the templates.268 269- Requires the memcache library from tummy__.269+ Requires the memcache library from `tummy`_ or the cmemcache library270+ from `Gijsbert de Haan`_.271 272 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.275 275- __ 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 """279 280 def __init__(self, use_memcache, memcache_time=60 * 60 * 24 * 7,281 memcache_host=None, item_prefix='template/', client=None):493 unmodified linesmodified:CHANGES+1 added-1 removed
71 unmodified lines72 - 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.75 76-- ``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``77 78 - `PackageLoader` can now work without pkg_resources too79 80 - added `getattribute` and `getitem` filter.130 unmodified linesmodified:MANIFEST.in+2 added-1 removed
1-include docs/build/*.html1 include Makefile CHANGES LICENSE AUTHORS TODO ez_setup.py2+include docs/build/*.html3+include docs/src/*.txt4 recursive-include tests *modified:setup.py+16 added-16 removed
51 unmodified lines52 print '=' * 7953 54 55 setup(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 lines75 '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 lines102 Extension('jinja._debugger', ['jinja/_debugger.c'])103 ]104 )105 },106- cmdclass = {'build_ext': optional_build_ext}106+ cmdclass={'build_ext': optional_build_ext}107 )