Applied documentation patches by Clemens Hermann.
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 02b42a8 · Browse files · 5 files·+22 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+22 added−23 removed
- other:+22 added−23 removed
Provenance
- Commit
0aa0f58- Tree
c2a9b78- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
02b42a8
5 files changed+22 added−23 removed
modified:docs/api.rst+4 added-4 removed
12 unmodified lines13 14 Jinja2 uses a central object called the template :class:`Environment`.15 Instances of this class are used to store the configuration, global objects16 and are used to load templates from the file system or other locations.17-Even if you are creating templates from string by using the constructor of17+Even if you are creating templates from strings by using the constructor of18 :class:`Template` class, an environment is created automatically for you,19 albeit a shared one.20 21 Most applications will create one :class:`Environment` object on application38 unmodified lines60 Python 2.x supports two ways of representing string objects. One is the61 `str` type and the other is the `unicode` type, both of which extend a type62 called `basestring`. Unfortunately the default is `str` which should not63 be used to store text based information unless only ASCII characters are64-used. With Python 2.6 it is possible to my `unicode` the default on a per64+used. With Python 2.6 it is possible to make `unicode` the default on a per65 module level and with Python 3 it will be the default.66 67 To explicitly use a unicode string you have to prefix the string literal68 with a `u`: ``u'Hänsel und Gretel sagen Hallo'``. That way Python will91 unmodified lines160 for filters or functions that may return undefined objects for161 some operations. All parameters except of `hint` should be provided162 as keyword parameters for better readability. The `hint` is used as163 error message for the exception if provided, otherwise the error164- message generated from `obj` and `name` automatically. The exception164+ message will be generated from `obj` and `name` automatically. The exception165 provided as `exc` is raised if something with the generated undefined166 object is done that the undefined object does not allow. The default167 exception is :exc:`UndefinedError`. If a `hint` is provided the168 `name` may be ommited.370 unmodified lines539 written on: {{ article.pub_date|datetimeformat }}540 publication date: {{ article.pub_date|datetimeformat('%d-%m-%Y') }}541 542 Filters can also be passed the current template context or environment. This543-is useful if a filters wants to return an undefined value or check the current543+is useful if a filter wants to return an undefined value or check the current544 :attr:`~Environment.autoescape` setting. For this purpose two decorators545 exist: :func:`environmentfilter` and :func:`contextfilter`.546 547 Here a small example filter that breaks a text into HTML line breaks and120 unmodified linesmodified:docs/intro.rst+1 added-1 removed
99 unmodified lines100 Or the new `pip`_ command::101 102 sudo pip install Jinja2==dev103 104-.. _download page: http://jinja.pocoo.org/2/download104+.. _download page: http://pypi.python.org/pypi/Jinja2105 .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools106 .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall107 .. _pip: http://pypi.python.org/pypi/pip108 .. _mercurial: http://www.selenic.com/mercurial/43 unmodified linesmodified:docs/templates.rst+11 added-12 removed
107 unmodified lines108 109 ``{{ name|striptags|title }}`` for example will remove all HTML Tags from the110 `name` and title-cases it. Filters that accept arguments have parentheses111 around the arguments, like a function call. This example will join a list112-by spaces: ``{{ list|join(', ') }}``.112+by commas: ``{{ list|join(', ') }}``.113 114 The :ref:`builtin-filters` below describes all the builtin filters.115 116 .. _tests:718 unmodified lines835 836 .. admonition:: Note837 838 In Jinja 2.0 the context that was passed to the included template839- did not include variables define in the template. As a matter of839+ did not include variables defined in the template. As a matter of840 fact this did not work::841 842 {% for box in boxes %}843 {% include "render_box.html" %}69 unmodified lines913 Math914 ~~~~915 916 Jinja allows you to calculate with values. This is rarely useful in templates917-but exists for completeness sake. The following operators are supported:917+but exists for completeness' sake. The following operators are supported:918 919 \+920- Adds two objects with each other. Usually numbers but if both objects are920+ Adds two objects together. Usually the objects are numbers but if both are921 strings or lists you can concatenate them this way. This however is not922 the preferred way to concatenate strings! For string concatenation have923 a look at the ``~`` operator. ``{{ 1 + 1 }}`` is ``2``.924 925 \-926- Substract two numbers from each other. ``{{ 3 - 2 }}`` is ``1``.926+ Substract the second number from the first one. ``{{ 3 - 2 }}`` is ``1``.927 928 /929 Divide two numbers. The return value will be a floating point number.930 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.2 unmodified lines933 Divide two numbers and return the truncated integer result.934 ``{{ 20 / 7 }}`` is ``2``.935 936 %937- Calculate the remainder of an integer division between the left and right938- operand. ``{{ 11 % 7 }}`` is ``4``.937+ Calculate the remainder of an integer division. ``{{ 11 % 7 }}`` is ``4``.938 939 \*940 Multiply the left operand with the right one. ``{{ 2 * 2 }}`` would942- return ``4``. This can also be used to repeat string multiple times.941+ return ``4``. This can also be used to repeat a string multiple times.942 ``{{ '=' * 80 }}`` would print a bar of 80 equal signs.943 944 \**945 Raise the left operand to the power of the right operand. ``{{ 2**3 }}``1 unmodified line947 948 Logic949 ~~~~~950 952-For `if` statements / `for` filtering or `if` expressions it can be useful to953-combine group multiple expressions:951+For `if` statements, `for` filtering or `if` expressions it can be useful to952+combine multiple expressions:953 954 and955 Return true if the left and the right operand is true.956 37 unmodified lines994 ``'John'``) ``Hello John!``.995 996 ()997 Call a callable: ``{{ post.render() }}``. Inside of the parentheses you999- can use arguments and keyword arguments like in python:998+ can use positional arguments and keyword arguments like in python:999 ``{{ post.render(user, full=true) }}``.1000 1001 . / []1002 Get an attribute of an object. (See :ref:`variables`)80 unmodified lines1083 works. Unlike `loop.cycle` however you can use this cycler outside of1084 loops or over multiple loops.1085 1086 This is for example very useful if you want to show a list of folders and1088- files, with the folders on top, but both in the same list with alteranting1087+ files, with the folders on top, but both in the same list with alternating1088 row colors.1089 1090 The following example shows how `cycler` can be used::1091 147 unmodified linesmodified:jinja2/environment.py+2 added-2 removed
654 unmodified lines655 vars, shared, self.globals, locals)656 657 def make_module(self, vars=None, shared=False, locals=None):658 """This method works like the :attr:`module` attribute when called659- without arguments but it will evaluate the template every call660- rather then caching the template. It's also possible to provide659+ without arguments but it will evaluate the template on every call660+ rather than caching it. It's also possible to provide661 a dict which is then used as context. The arguments are the same662 as for the :meth:`new_context` method.663 """664 return TemplateModule(self, self.new_context(vars, shared, locals))176 unmodified linesmodified:jinja2/filters.py+4 added-4 removed
283 unmodified lines284 285 def do_filesizeformat(value, binary=False):286 """Format the value like a 'human-readable' file size (i.e. 13 KB,287 4.1 MB, 102 bytes, etc). Per default decimal prefixes are used (mega,288- giga etc.), if the second parameter is set to `True` the binary289- prefixes are (mebi, gibi).288+ giga, etc.), if the second parameter is set to `True` the binary289+ prefixes are used (mebi, gibi).290 """291 bytes = float(value)292 base = binary and 1024 or 1000293 middle = binary and 'i' or ''157 unmodified lines451 452 def do_slice(value, slices, fill_with=None):453 """Slice an iterator and return a list of lists containing454 those items. Useful if you want to create a div containing455- three div tags that represent columns:455+ three ul tags that represent columns:456 457 .. sourcecode:: html+jinja458 459 <div class="columwrapper">37 unmodified lines497 <table>498 {%- for row in items|batch(3, ' ') %}499 <tr>500 {%- for column in row %}501- <tr>{{ column }}</td>501+ <td>{{ column }}</td>502 {%- endfor %}503 </tr>504 {%- endfor %}505 </table>210 unmodified lines