Skip to content
Myr

Fixed typos in documentation

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

--HG-- branch : trunk

authored by Lukas Meuser · committed by Lukas Meuser · parent 187bde1 · Browse files · 6 files+33 added−29 removed
This commit

State

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

Diff stats

6 files+33 added−29 removed

  • other:+33 added−29 removed

6 files+33 added−29 removed

modified:docs/api.rst+3 added-3 removed
70 unmodified lines
71 see :ref:`writing-filters`.7273 .. attribute:: tests7475 A dict of test funcitons for this environment. As long as no76 template way loaded it's safe to modify this dict. For custom tests75 A dict of test functions for this environment. As long as no76 template was loaded it's safe to modify this dict. For custom tests77 see :ref:`writing-tests`.7879 .. attribute:: globals8081 A dict of global variables. These variables are always available82 in a template and (if the optimizer is enabled) may not be83 override by templates. As long as no template was loaded it's safe83 overridden by templates. As long as no template was loaded it's safe84 to modify this dict. For more details see :ref:`global-namespace`.858687.. autoclass:: jinja2.Template
249 unmodified lines
modified:docs/templates.rst+20 added-19 removed
98 unmodified lines
99Beside filters there are also so called "tests" available. Tests can be used100to test a variable against a common expression. To test a variable or101expression you add `is` plus the name of the test after the variable. For102example to find out if a variable is defined you can do ``name is defined``103which will then return true or false depening on if `name` is defined.103which will then return true or false depending on if `name` is defined.104105Tests can accept arguments too. If the test only takes one argument you can106leave out the parentheses to group them. For example the following two107expressions do the same::108109 {% if loop.index is divisibleby 3 %}110 {% if loop.index is divisibleby(3) %}111112The :ref:`builtin-tests` below descibes all the builtin tests.112The :ref:`builtin-tests` below describes all the builtin tests.113114115Comments116--------
157 unmodified lines
274of tainted values so the information if a value is safe or unsafe can get275lost. If the information is lost escaping will take place which means that276you could end up with double escaped contents.277278Double escaping is easy to avoid however, just relay on the tools Jinja2278Double escaping is easy to avoid however, just rely on the tools Jinja2279provides and don't use builtin Python constructs such as the string modulo280operator.281282Functions returning template data (macros, `super`, `self.BLOCKNAME`) return
14 unmodified lines
297298For299~~~300301Loop over each item in a sequece. For example, to display a list of users301Loop over each item in a sequence. For example, to display a list of users302provided in a variable called `users`::303304 <h1>Members</h1>305 <ul>
26 unmodified lines
332| `loop.cycle` | A helper function to cycle between a list of |333| | sequences. See the explanation below. |334+-----------------------+---------------------------------------------------+335336Within a for-loop, it's psosible to cycle among a list of strings/variables336Within a for-loop, it's possible to cycle among a list of strings/variables337each time through the loop by using the special `loop.cycle` helper::338339 {% for row in rows %}340 <li class="{{ loop.cycle('odd', 'even') }}">{{ row }}</li>
57 unmodified lines
398399Macros400~~~~~~401402Macros comparable with functions in regular programming languages. They are403useful to put often used idoms into reusable functions to not repeat yourself.402Macros are comparable with functions in regular programming languages. They403are useful to put often used idioms into reusable functions to not repeat404yourself.405405Macros can be defined in helper templates with then are :ref:`imported <import>`406or directly in the template where they are used. There is one big difference407between those two possibilities. A macro that is defined in the template where408it's also used has access to the context passed to the template. A macro409defined in another template and then imported can only access variables defined410there or in the global context.406Macros can be defined in helper templates which then are :ref:`imported407<import>` or directly in the template where they are used. There is one big408difference between those two possibilities. A macro that is defined in the409template where it's also used has access to the context passed to the template.410A macro defined in another template and then imported can only access variables411defined there or in the global context.412413Here a small example of a macro that renders a form element::414415 {% macro input(name, value='', type='text', size=20) -%}
5 unmodified lines
421422 <p>{{ input('username') }}</p>423 <p>{{ input('password', type='password') }}</p>424424If the macro was defiend in a different template you have to425If the macro was defined in a different template you have to426:ref:`import <import>` it first.427428Inside macros you have access to three special variables:429430`varargs`430 If more positional arguments are passed to the macro then accepted by the431 If more positional arguments are passed to the macro than accepted by the432 macro they end up in the special `varargs` variable as list of values.433434`kwargs`435 Like `varargs` but for keyword arguments. All unconsumed keyword436 arguments are stored in this special variable.437438`caller`438 If the macro was called from a :ref:`call` tag the caller is stored in439 this variable as macro which can be called.439 If the macro was called from a :ref:`call<call>` tag the caller is stored440 in this variable as macro which can be called.441442Macros also expose some of their internal details. The following attributes443are available on a macro object:444
15 unmodified lines
460 accesses the special `varargs` variable).461462`caller`463 This is `true` if the macro accesses the special `caller` variable and may463 be called from a :ref:`call` tag.464 be called from a :ref:`call<call>` tag.465466467.. _call:468
181 unmodified lines
650 only has one item you have to end it with a comma. Tuples are usually651 used to represent items of two or more elements. See the example above652 for more details.653653{'dict': 'of', 'keys': 'and', 'value': 'pairs'}:654{'dict': 'of', 'key': 'and', 'value': 'pairs'}:655 A dict in Python is a structure that combines keys and values. Keys must656 be unique and always have exactly one value. Dicts are rarely used in657 templates, they are useful in some rare cases such as the :func:`xmlattr`658 filter.
161 unmodified lines
modified:jinja2/environment.py+3 added
89 unmodified lines
9091 `variable_start_string`92 The string marking the begin of a print statement.93 Defaults to ``'{{'``.94 95 `variable_stop_string`96 The string marking the end of a print statement. Defaults to ``'}}'``.9798 `comment_start_string`99 The string marking the begin of a comment. Defaults to ``'{#'``.100
560 unmodified lines
modified:jinja2/filters.py+2 added-2 removed
199 unmodified lines
200@environmentfilter201def do_join(environment, value, d=u''):202 """Return a string which is the concatenation of the strings in the203 sequence. The separator between elements is an empty string per204 default, you can define ith with the optional parameter:204 default, you can define it with the optional parameter:205206 .. sourcecode:: jinja207208 {{ [1, 2, 3]|join('|') }}
32 unmodified lines
241242243@environmentfilter244def do_first(environment, seq):245 """Return the frist item of a sequence."""245 """Return the first item of a sequence."""246 try:247 return iter(seq).next()248 except StopIteration:249 return environment.undefined('No first item, sequence was empty.')
424 unmodified lines
modified:jinja2/tests.py+1 added-1 removed
20 unmodified lines
21 return value % 2 == 1222324def test_even(value):25 """Return true of the variable is even."""25 """Return true if the variable is even."""26 return value % 2 == 0272829def test_divisibleby(value, num):
107 unmodified lines
modified:jinja2/utils.py+4 added-4 removed
406 unmodified lines
407# markup type which is define above.408try:409 from jinja2._speedups import escape, soft_unicode410except ImportError:411 def escape(obj):411 def escape(s):412 """Convert the characters &, <, >, and " in string s to HTML-safe413 sequences. Use this if you need to display text that might contain414 such characters in HTML.415 """416 if hasattr(obj, '__html__'):417 return obj.__html__()418 return Markup(unicode(obj)416 if hasattr(s, '__html__'):417 return s.__html__()418 return Markup(unicode(s)419 .replace('&', '&amp;')420 .replace('>', '&gt;')421 .replace('<', '&lt;')422 .replace('"', '&quot;')
23 unmodified lines