From: Armin Ronacher Date: Mon, 28 Apr 2008 16:30:27 +0000 (+0200) Subject: fixed another python2.4 bug X-Git-Tag: 2.0rc1~122 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=316157de45e2b1772de81baa6addfb28a969f9c7;p=jinja2.git fixed another python2.4 bug --HG-- branch : trunk --- diff --git a/docs/templates.rst b/docs/templates.rst index f4ca714..280b166 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -438,19 +438,19 @@ Literals The simplest form of expressions are literals. Literals are representations for Python objects such as strings and numbers. The following literals exist: -``"Hello World"`` +"Hello World": Everything between two double or single quotes is a string. They are useful whenever you need a string in the template (for example as arguments to function calls, filters or just to extend or include a template). -``42`` / ``42.23`` +42 / 42.23: Integers and floating point numbers are created by just writing the number down. If a dot is present the number is a float, otherwise an integer. Keep in mind that for Python ``42`` and ``42.0`` is something different. -``['list', 'of', 'objects']`` +['list', 'of', 'objects']: Everything between two brackets is a list. Lists are useful to store sequential data in or to iterate over them. For example you can easily create a list of links using lists and tuples with a for loop. @@ -464,19 +464,19 @@ for Python objects such as strings and numbers. The following literals exist: {% endfor %} -``('tuple', 'of', 'values')`` +('tuple', 'of', 'values'): Tuples are like lists, just that you can't modify them. If the tuple only has one item you have to end it with a comma. Tuples are usually used to represent items of two or more elements. See the example above for more details. -``{'dict': 'of', 'keys': 'and', 'value': 'pairs'}`` +{'dict': 'of', 'keys': 'and', 'value': 'pairs'}: A dict in Python is a structure that combines keys and values. Keys must be unique and always have exactly one value. Dicts are rarely used in templates, they are useful in some rare cases such as the :func:`xmlattr` filter. -``true`` and ``false`` +true / false: true is always true and false is always false. Keep in mind that those literals are lowercase! @@ -486,33 +486,33 @@ Math Jinja allows you to calculate with values. This is rarely useful in templates but exists for completeness sake. The following operators are supported: -``+`` +\+ Adds two objects with each other. Usually numbers but if both objects are strings or lists you can concatenate them this way. This however is not the preferred way to concatenate strings! For string concatenation have a look at the ``~`` operator. ``{{ 1 + 1 }}`` is ``2``. -``-`` +\- Substract two numbers from each other. ``{{ 3 - 2 }}`` is ``1``. -``/`` +/ Divide two numbers. The return value will be a floating point number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``. -``//`` +// Divide two numbers and return the truncated integer result. ``{{ 20 / 7 }}`` is ``2``. -``%`` +% Calculate the remainder of an integer division between the left and right operand. ``{{ 11 % 7 }}`` is ``4``. -``*`` +\* Multiply the left operand with the right one. ``{{ 2 * 2 }}`` would return ``4``. This can also be used to repeat string multiple times. ``{{ '=' * 80 }}`` would print a bar of 80 equal signs. -``**`` +\** Raise the left operand to the power of the right operand. ``{{ 2**3 }}`` would return ``8``. @@ -522,16 +522,16 @@ Logic For `if` statements / `for` filtering or `if` expressions it can be useful to combine group multiple expressions: -``and`` +and Return true if the left and the right operand is true. -``or`` +or Return true if the left or the right operand is true. -``not`` +not negate a statement (see below). -``()`` (group) +(expr) group an expression. Note that there is no support for any bit operations or something similar. @@ -548,28 +548,28 @@ Other Operators The following operators are very useful but don't fit into any of the other two categories: -``in`` +in Perform sequence / mapping containment test. Returns true if the left operand is contained in the right. ``{{ 1 in [1, 2, 3] }}`` would for example return true. -``is`` - Performs a :ref:`tests `. +is + Performs a :ref:`test `. -``|`` - Applies a :ref:`filters `. +\| + Applies a :ref:`filter `. -``~`` +~ Converts all operands into strings and concatenates them. ``{{ "Hello " ~ name ~ "!" }}`` would return (assuming `name` is ``'John'``) ``Hello John!``. -``()`` (call) +() Call a callable: ``{{ post.render() }}``. Inside of the parentheses you can use arguments and keyword arguments like in python: ``{{ post.render(user, full=true) }}``. -``.`` / ``[]`` +. / [] Get an attribute of an object. (See :ref:`variables`) diff --git a/jinja2/utils.py b/jinja2/utils.py index 80a6b87..f375529 100644 --- a/jinja2/utils.py +++ b/jinja2/utils.py @@ -248,14 +248,15 @@ class Markup(unicode): for method in '__getitem__', '__getslice__', 'capitalize', \ 'title', 'lower', 'upper', 'replace', 'ljust', \ 'rjust', 'lstrip', 'rstrip', 'center', 'strip', \ - 'translate', 'expandtabs', 'rpartition', 'swapcase', \ - 'zfill': + 'translate', 'expandtabs', 'swapcase', 'zfill': locals()[method] = make_wrapper(method) # new in python 2.5 if hasattr(unicode, 'partition'): - locals().update(partition=make_wrapper('partition'), - rpartition=make_wrapper('rpartition')) + locals().update( + partition=make_wrapper('partition'), + rpartition=make_wrapper('rpartition') + ) del method, make_wrapper