Commit ddfd70a7 authored by alexpott's avatar alexpott

Issue #2363741 by joelpittet: Upgrade Twig to 1.16.* from 1.15.*.

parent 455a6a6f
......@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "838f4566f4f537d5f71fa46b66f263b0",
"hash": "4378dea31ef5185651bc10bd9a40e591",
"packages": [
{
"name": "doctrine/annotations",
......@@ -2373,16 +2373,16 @@
},
{
"name": "twig/twig",
"version": "v1.15.1",
"version": "v1.16.2",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig.git",
"reference": "1fb5784662f438d7d96a541e305e28b812e2eeed"
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/1fb5784662f438d7d96a541e305e28b812e2eeed",
"reference": "1fb5784662f438d7d96a541e305e28b812e2eeed",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc",
"shasum": ""
},
"require": {
......@@ -2391,7 +2391,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
"dev-master": "1.16-dev"
}
},
"autoload": {
......@@ -2426,7 +2426,7 @@
"keywords": [
"templating"
],
"time": "2014-02-13 10:19:29"
"time": "2014-10-17 12:53:44"
},
{
"name": "zendframework/zend-escaper",
......
......@@ -1304,65 +1304,6 @@
"spl"
]
},
{
"name": "twig/twig",
"version": "v1.15.1",
"version_normalized": "1.15.1.0",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig.git",
"reference": "1fb5784662f438d7d96a541e305e28b812e2eeed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/1fb5784662f438d7d96a541e305e28b812e2eeed",
"reference": "1fb5784662f438d7d96a541e305e28b812e2eeed",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"time": "2014-02-13 10:19:29",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Twig_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
},
{
"name": "Twig Team",
"homepage": "https://github.com/fabpot/Twig/graphs/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "http://twig.sensiolabs.org",
"keywords": [
"templating"
]
},
{
"name": "doctrine/annotations",
"version": "v1.2.1",
......@@ -2646,5 +2587,64 @@
"rest",
"web service"
]
},
{
"name": "twig/twig",
"version": "v1.16.2",
"version_normalized": "1.16.2.0",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig.git",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc",
"reference": "42f758d9fe2146d1f0470604fc05ee43580873fc",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"time": "2014-10-17 12:53:44",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Twig_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
},
{
"name": "Twig Team",
"homepage": "https://github.com/fabpot/Twig/graphs/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "http://twig.sensiolabs.org",
"keywords": [
"templating"
]
}
]
......@@ -5,6 +5,7 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
env:
......
* 1.15.1 (2013-02-13)
* 1.16.2 (2014-10-17)
* fixed timezone on dates as strings
* fixed 2-words test names when a custom node class is not used
* fixed macros when using an argument named like a PHP super global (like GET or POST)
* fixed date_modify when working with DateTimeImmutable
* optimized for loops
* fixed multi-byte characters handling in the split filter
* fixed a regression in the in operator
* fixed a regression in the slice filter
* 1.16.1 (2014-10-10)
* improved error reporting in a sandboxed template
* fixed missing error file/line information under certain circumstances
* fixed wrong error line number in some error messages
* fixed the in operator to use strict comparisons
* sped up the slice filter
* fixed for mb function overload mb_substr acting different
* fixed the attribute() function when passing a variable for the arguments
* 1.16.0 (2014-07-05)
* changed url_encode to always encode according to RFC 3986
* fixed inheritance in a 'use'-hierarchy
* removed the __toString policy check when the sandbox is disabled
* fixed recursively calling blocks in templates with inheritance
* 1.15.1 (2014-02-13)
* fixed the conversion of the special '0000-00-00 00:00' date
* added an error message when trying to import an undefined block from a trait
......
......@@ -36,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
"dev-master": "1.16-dev"
}
}
}
......@@ -166,21 +166,6 @@ Namespaced templates can be accessed via the special
$twig->render('@admin/index.html', array());
``Twig_Loader_String``
......................
``Twig_Loader_String`` loads templates from strings. It's a dummy loader as
the template reference is the template source code::
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);
echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
This loader should only be used for unit testing as it has severe limitations:
several tags, like ``extends`` or ``include`` do not make sense to use as the
reference to the template is the template source code itself.
``Twig_Loader_Array``
.....................
......@@ -214,7 +199,7 @@ projects where storing all templates in a single PHP file might make sense.
'base.html' => '{% block content %}{% endblock %}',
));
$loader2 = new Twig_Loader_Array(array(
'index.html' => '{% extends "base.twig" %}{% block content %}Hello {{ name }}{% endblock %}',
'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}',
'base.html' => 'Will never be loaded',
));
......@@ -268,26 +253,6 @@ All loaders implement the ``Twig_LoaderInterface``::
function isFresh($name, $time);
}
As an example, here is how the built-in ``Twig_Loader_String`` reads::
class Twig_Loader_String implements Twig_LoaderInterface
{
public function getSource($name)
{
return $name;
}
public function getCacheKey($name)
{
return $name;
}
public function isFresh($name, $time)
{
return false;
}
}
The ``isFresh()`` method must return ``true`` if the current cached template
is still fresh, given the last modification time, or ``false`` otherwise.
......
......@@ -23,8 +23,8 @@ Extensions
PEAR
----
PEAR support will be discontinued in Twig 2.0, and no PEAR packages will be
provided. Use Composer instead.
PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are
provided anymore. Use Composer instead.
Filters
-------
......@@ -80,6 +80,12 @@ Tests
* The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same
as`` and ``divisible by`` respectively.
Nodes
-----
* As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig
2.0.
Interfaces
----------
......
......@@ -2,7 +2,7 @@
=========
.. versionadded:: 1.12.3
The batch filter was added in Twig 1.12.3.
The ``batch`` filter was added in Twig 1.12.3.
The ``batch`` filter "batches" items by returning a list of lists with the
given number of items. If you provide a second parameter, it is used to fill
......
......@@ -21,8 +21,8 @@ is the input charset:
Arguments
---------
* ``from``: The input charset
* ``to``: The output charset
* ``from``: The input charset
.. _`iconv`: http://php.net/iconv
.. _`mbstring`: http://php.net/mbstring
......@@ -2,7 +2,7 @@
=========
.. versionadded:: 1.12.2
The first filter was added in Twig 1.12.2.
The ``first`` filter was added in Twig 1.12.2.
The ``first`` filter returns the first "element" of a sequence, a mapping, or
a string:
......
``json_encode``
===============
The ``json_encode`` filter returns the JSON representation of a string:
The ``json_encode`` filter returns the JSON representation of a value:
.. code-block:: jinja
......
......@@ -2,7 +2,7 @@
========
.. versionadded:: 1.12.2
The last filter was added in Twig 1.12.2.
The ``last`` filter was added in Twig 1.12.2.
The ``last`` filter returns the last "element" of a sequence, a mapping, or
a string:
......
``length``
==========
The ``length`` filters returns the number of items of a sequence or mapping, or
The ``length`` filter returns the number of items of a sequence or mapping, or
the length of a string:
.. code-block:: jinja
......
......@@ -39,3 +39,9 @@ overridden.
{% set items = { 'apple': 'unknown' }|merge(items) %}
{# items now contains { 'apple': 'fruit', 'orange': 'fruit' } #}
.. note::
Internally, Twig uses the PHP `array_merge`_ function.
.. _`array_merge`: http://php.net/array_merge
......@@ -2,7 +2,7 @@
=========
.. versionadded:: 1.5
The nl2br filter was added in Twig 1.5.
The ``nl2br`` filter was added in Twig 1.5.
The ``nl2br`` filter inserts HTML line breaks before all newlines in a string:
......
......@@ -2,7 +2,7 @@
=================
.. versionadded:: 1.5
The number_format filter was added in Twig 1.5
The ``number_format`` filter was added in Twig 1.5
The ``number_format`` filter formats numbers. It is a wrapper around PHP's
`number_format`_ function:
......
......@@ -10,3 +10,27 @@ if ``raw`` is the last filter applied to it:
{% autoescape %}
{{ var|raw }} {# var won't be escaped #}
{% endautoescape %}
.. note::
Be careful when using the ``raw`` filter inside expressions:
.. code-block:: jinja
{% autoescape %}
{% set hello = '<strong>Hello</strong>' %}
{% set hola = '<strong>Hola</strong>' %}
{{ false ? '<strong>Hola</strong>' : hello|raw }}
does not render the same as
{{ false ? hola : hello|raw }}
but renders the same as
{{ (false ? hola : hello)|raw }}
{% endautoescape %}
The first ternary statement is not escaped: ``hello`` is marked as being
safe and Twig does not escape static values (see
:doc:`escape<../tags/autoescape>`). In the second ternary statement, even
if ``hello`` is marked as safe, ``hola`` remains unsafe and so is the whole
expression. The third ternary statement is marked as safe and the result is
not escaped.
......@@ -2,7 +2,7 @@
===========
.. versionadded:: 1.6
The slice filter was added in Twig 1.6.
The ``slice`` filter was added in Twig 1.6.
The ``slice`` filter extracts a slice of a sequence, a mapping, or a string:
......@@ -41,7 +41,7 @@ As syntactic sugar, you can also use the ``[]`` notation:
{{ '12345'[2:] }} {# will display "345" #}
The ``slice`` filter works as the `array_slice`_ PHP function for arrays and
`substr`_ for strings.
`mb_substr`_ for strings with a fallback to `substr`_.
If the start is non-negative, the sequence will start at that start in the
variable. If start is negative, the sequence will start that far from the end
......@@ -67,4 +67,5 @@ Arguments
.. _`Traversable`: http://php.net/manual/en/class.traversable.php
.. _`array_slice`: http://php.net/array_slice
.. _`mb_substr` : http://php.net/mb-substr
.. _`substr`: http://php.net/substr
......@@ -2,15 +2,15 @@
=========
.. versionadded:: 1.10.3
The split filter was added in Twig 1.10.3.
The ``split`` filter was added in Twig 1.10.3.
The ``split`` filter splits a string by the given delimiter and returns a list
of strings:
.. code-block:: jinja
{{ "one,two,three"|split(',') }}
{# returns ['one', 'two', 'three'] #}
{% set foo = "one,two,three"|split(',') %}
{# foo contains ['one', 'two', 'three'] #}
You can also pass a ``limit`` argument:
......@@ -24,19 +24,19 @@ You can also pass a ``limit`` argument:
.. code-block:: jinja
{{ "one,two,three,four,five"|split(',', 3) }}
{# returns ['one', 'two', 'three,four,five'] #}
{% set foo = "one,two,three,four,five"|split(',', 3) %}
{# foo contains ['one', 'two', 'three,four,five'] #}
If the ``delimiter`` is an empty string, then value will be split by equal
chunks. Length is set by the ``limit`` argument (one character by default).
.. code-block:: jinja
{{ "123"|split('') }}
{# returns ['1', '2', '3'] #}
{% set foo = "123"|split('') %}
{# foo contains ['1', '2', '3'] #}
{{ "aabbcc"|split('', 2) }}
{# returns ['aa', 'bb', 'cc'] #}
{% set bar = "aabbcc"|split('', 2) %}
{# bar contains ['aa', 'bb', 'cc'] #}
.. note::
......
......@@ -2,7 +2,7 @@
========
.. versionadded:: 1.6.2
The trim filter was added in Twig 1.6.2.
The ``trim`` filter was added in Twig 1.6.2.
The ``trim`` filter strips whitespace (or other characters) from the beginning
and end of a string:
......
......@@ -4,6 +4,10 @@
.. versionadded:: 1.12.3
Support for encoding an array as query string was added in Twig 1.12.3.
.. versionadded:: 1.16.0
The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes
according to RFC 3986.
The ``url_encode`` filter percent encodes a given string as URL segment
or an array as query string:
......@@ -12,7 +16,7 @@ or an array as query string:
{{ "path-seg*ment"|url_encode }}
{# outputs "path-seg%2Ament" #}
{{ "string with spaces"|url_encode(true) }}
{{ "string with spaces"|url_encode }}
{# outputs "string%20with%20spaces" #}
{{ {'param': 'value', 'foo': 'bar'}|url_encode }}
......@@ -21,7 +25,9 @@ or an array as query string:
.. note::
Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass
``true`` as the first parameter) or the `http_build_query`_ function.
``true`` as the first parameter) or the `http_build_query`_ function. Note
that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the
``raw`` argument was removed.)
.. _`urlencode`: http://php.net/urlencode
.. _`rawurlencode`: http://php.net/rawurlencode
......
......@@ -15,7 +15,7 @@ Converts an argument to a date to allow date comparison:
{# do something #}
{% endif %}
The argument must be in a format supported by the `date`_ function.
The argument must be in one of PHP’s supported `date and time formats`_.
You can pass a timezone as the second argument:
......@@ -49,4 +49,4 @@ Arguments
* ``date``: The date
* ``timezone``: The timezone
.. _`date`: http://www.php.net/date
.. _`date and time formats`: http://php.net/manual/en/datetime.formats.php
......@@ -2,7 +2,7 @@
========
.. versionadded:: 1.5
The dump function was added in Twig 1.5.
The ``dump`` function was added in Twig 1.5.
The ``dump`` function dumps information about a template variable. This is
mostly useful to debug a template that does not behave as expected by
......
......@@ -2,7 +2,7 @@
===========
.. versionadded:: 1.12
The include function was added in Twig 1.12.
The ``include`` function was added in Twig 1.12.
The ``include`` function returns the rendered content of a template:
......
......@@ -15,5 +15,6 @@ When called with a mapping, max ignores keys and only compares values:
.. code-block:: jinja
{{ max({2: "two", 1: "one", 3: "three", 5: "five", 4: "for"}) }}
{# return "two" #}
{{ max({2: "e", 1: "a", 3: "b", 5: "d", 4: "c"}) }}
{# returns "e" #}
......@@ -15,5 +15,6 @@ When called with a mapping, min ignores keys and only compares values:
.. code-block:: jinja
{{ min({2: "two", 1: "one", 3: "three", 5: "five", 4: "for"}) }}
{# return "five" #}
{{ min({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) }}
{# returns "a" #}
......@@ -2,7 +2,7 @@
==========
.. versionadded:: 1.5
The random function was added in Twig 1.5.
The ``random`` function was added in Twig 1.5.
.. versionadded:: 1.6
String and integer handling was added in Twig 1.6.
......
......@@ -2,7 +2,7 @@
==========
.. versionadded:: 1.15
The source function was added in Twig 1.15.
The ``source`` function was added in Twig 1.15.
The ``source`` function returns the content of a template without rendering it:
......
......@@ -2,7 +2,7 @@
========================
.. versionadded:: 1.11
The template_from_string function was added in Twig 1.11.
The ``template_from_string`` function was added in Twig 1.11.
The ``template_from_string`` function loads a template from a string:
......
......@@ -5,15 +5,15 @@ Twig
:maxdepth: 2
intro
installation
templates
api
advanced
internals
deprecated
recipes
coding_standards
tags/index
filters/index
functions/index
tests/index
installation
deprecated
......@@ -9,51 +9,39 @@ Installing the Twig PHP package
Installing via Composer (recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Install Composer in your project:
Install `Composer`_ and run the following command to get the latest version:
.. code-block:: bash
curl -s http://getcomposer.org/installer | php
2. Create a ``composer.json`` file in your project root:
.. code-block:: javascript
{
"require": {
"twig/twig": "1.*"
}
}
3. Install via Composer
.. code-block:: bash
php composer.phar install
.. note::
If you want to learn more about Composer, the ``composer.json`` file syntax
and its usage, you can read the `online documentation`_.
composer require twig/twig:~1.0
Installing from the tarball release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Download the most recent tarball from the `download page`_
2. Unpack the tarball
3. Move the files somewhere in your project