Merge branch '2.x' into 3.x

* 2.x:
  Move country_timezone to a function
  Renamed inky to inky_to_html
  Minor fix in a filter description
  Minor fixes in the docs of some intl filters
This commit is contained in:
Fabien Potencier
2019-09-07 14:46:43 +02:00
14 changed files with 40 additions and 34 deletions
+3 -3
View File
@@ -23,12 +23,12 @@
* added support for an "arrow" function on the "sort" filter
* added the CssInliner extension in the "extra" repositories: "inline_css"
filter
* added the Inky extension in the "extra" repositories: "inky" filter
* added the Inky extension in the "extra" repositories: "inky_to_html" filter
* added Intl extension in the "extra" repositories: "country_name",
"currency_name", "currency_symbol", "language_name", "locale_name",
"timezone_name", "country_timezones", "format_currency", "format_number",
"timezone_name", "format_currency", "format_number",
"format_*_number", "format_datetime", "format_date", and "format_time"
filters
filters, and the "country_timezones" function
* added the Markdown extension in the "extra" repositories: "markdown_to_html",
and "html_to_markdown" filters
* added the HtmlExtension extension in the "extra" repositories: "date_uri"
+1 -1
View File
@@ -4,7 +4,7 @@
.. versionadded:: 2.12
The ``currency_symbol`` filter was added in Twig 2.12.
The ``currency_symbol`` filter returns the currency name given its three-letter
The ``currency_symbol`` filter returns the currency symbol given its three-letter
code:
.. code-block:: twig
+1 -2
View File
@@ -10,7 +10,6 @@ Filters
column
convert_encoding
country_name
country_timezones
currency_name
currency_symbol
data_uri
@@ -28,7 +27,7 @@ Filters
format_time
html_to_markdown
inline_css
inky
inky_to_html
join
json_encode
keys
@@ -1,15 +1,15 @@
``inky``
========
``inky_to_html``
================
.. versionadded:: 2.12
The ``inky`` filter was added in Twig 2.12.
The ``inky_to_html`` filter was added in Twig 2.12.
The ``inky`` filter processes an `inky email template
The ``inky_to_html`` filter processes an `inky email template
<https://github.com/zurb/inky>`_:
.. code-block:: twig
{% apply inky %}
{% apply inky_to_html %}
<row>
<columns large="6"></columns>
<columns large="6"></columns>
@@ -20,11 +20,11 @@ You can also use the filter on an included file:
.. code-block:: twig
{{ include('some_template.inky.twig')|inky }}
{{ include('some_template.inky.twig')|inky_to_html }}
.. note::
The ``inky`` filter is part of the ``CssInlinerExtension`` which is not
The ``inky_to_html`` filter is part of the ``CssInlinerExtension`` which is not
installed by default. Install it first:
.. code-block:: bash
+1 -2
View File
@@ -4,8 +4,7 @@
.. versionadded:: 2.12
The ``timezone_name`` filter was added in Twig 2.12.
The ``timezone_name`` filter returns the timezone name given its two-letter
code:
The ``timezone_name`` filter returns the timezone name given a timezone identifier:
.. code-block:: twig
@@ -2,19 +2,19 @@
=====================
.. versionadded:: 2.12
The ``country_timezones`` filter was added in Twig 2.12.
The ``country_timezones`` function was added in Twig 2.12.
The ``country_timezones`` filter returns the names of the countries associated
with a given timezone:
The ``country_timezones`` function returns the names of the timezones associated
with a given country code:
.. code-block:: twig
{# Europe/Paris #}
{{ 'FR'|country_timezones|join(', ') }}
{{ country_timezones('FR')|join(', ') }}
.. note::
The ``country_timezones`` filter is part of the ``IntlExtension`` which is not
The ``country_timezones`` function is part of the ``IntlExtension`` which is not
installed by default. Install it first:
.. code-block:: bash
+1
View File
@@ -18,4 +18,5 @@ Functions
random
range
source
country_timezones
template_from_string
@@ -1,5 +1,5 @@
--TEST--
"inky" filter
"inline_css" filter
--TEMPLATE--
{% apply inline_css|spaceless %}
<html>
+1 -2
View File
@@ -12,7 +12,6 @@
namespace Twig\Extra\Inky;
use Pinky;
use Twig\Error\RuntimeError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@@ -21,7 +20,7 @@ class InkyExtension extends AbstractExtension
public function getFilters()
{
return [
new TwigFilter('inky', 'Twig\\Extra\\Inky\\twig_inky', ['is_safe' => ['html']]),
new TwigFilter('inky_to_html', 'Twig\\Extra\\Inky\\twig_inky', ['is_safe' => ['html']]),
];
}
}
+3 -3
View File
@@ -1,11 +1,11 @@
--TEST--
"inky" filter
"inky_to_html" filter
--TEMPLATE--
{% apply inky %}
{% apply inky_to_html %}
<container class="extra">{{ var }}</container>
{%- endapply %}
{{ include("inky")|inky }}
{{ include("inky")|inky_to_html }}
--TEMPLATE(inky)--
<container class="extra">{{ var }}</container>
--DATA--
+1 -1
View File
@@ -9,7 +9,7 @@ This package is a Twig extension that provides the following:
* [`language_name`][4] filter: returns the language name given its two-letter code;
* [`locale_name`][5] filter: returns the language name given its two-letter code;
* [`timezone_name`][6] filter: returns the timezone name given its identifier;
* [`country_timezones`][7] filter: returns the names of the countries associated with a given timezone;
* [`country_timezones`][7] filter: returns the timezone identifiers of the given country code;
* [`format_currency`][8] filter: formats a number as a currency;
* [`format_number`][9] filter: formats a number;
* [`format_datetime`][10] filter: formats a date time;
+9 -1
View File
@@ -20,6 +20,7 @@ use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
final class IntlExtension extends AbstractExtension
{
@@ -134,7 +135,6 @@ final class IntlExtension extends AbstractExtension
new TwigFilter('language_name', [$this, 'getLanguageName']),
new TwigFilter('locale_name', [$this, 'getLocaleName']),
new TwigFilter('timezone_name', [$this, 'getTimezoneName']),
new TwigFilter('country_timezones', [$this, 'getCountryTimezones']),
// localized formatters
new TwigFilter('format_currency', [$this, 'formatCurrency']),
@@ -146,6 +146,14 @@ final class IntlExtension extends AbstractExtension
];
}
public function getFunctions()
{
return [
// internationalized names
new TwigFunction('country_timezones', [$this, 'getCountryTimezones']),
];
}
public function getCountryName(string $country, string $locale = null): string
{
return Countries::getName($country, $locale);
@@ -1,8 +1,8 @@
--TEST--
"country_timezones" filter
"country_timezones" function
--TEMPLATE--
{{ 'FR'|country_timezones|join(', ') }}
{{ 'US'|country_timezones|join(', ') }}
{{ country_timezones('FR')|join(', ') }}
{{ country_timezones('US')|join(', ') }}
--DATA--
return [];
--EXPECT--
+3 -3
View File
@@ -41,12 +41,12 @@ final class Extensions
'class' => IntlExtension::class,
'class_name' => 'IntlExtension',
'package' => 'twig/intl-extra',
'filters' => ['country_name', 'currency_name', 'currency_symbol', 'language_name', 'country_timezones',
'filters' => ['country_name', 'currency_name', 'currency_symbol', 'language_name',
'format_currency', 'format_number', 'format_decimal_number', 'format_currency_number',
'format_percent_number', 'format_scientific_number', 'format_spellout_number', 'format_ordinal_number',
'format_duration_number', 'format_date', 'format_datetime', 'format_time',
],
'functions' => [],
'functions' => ['country_timezones'],
],
'cssinliner' => [
'name' => 'cssinliner',
@@ -61,7 +61,7 @@ final class Extensions
'class' => InkyExtension::class,
'class_name' => 'InkyExtension',
'package' => 'twig/inky-extra',
'filters' => ['inky'],
'filters' => ['inky_to_html'],
'functions' => [],
],
];