From: Fabien Potencier Date: Mon, 20 Dec 2010 07:40:02 +0000 (+0100) Subject: converted the constant filter to a function X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=47a73476e03def89dcf86674efaf97e1f30c5e35;p=web%2Fkonrad%2Ftwig.git converted the constant filter to a function --- diff --git a/CHANGELOG b/CHANGELOG index d58f697..80b7381 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Backward incompatibilities: * the items filter, which has been deprecated for quite a long time now, has been removed * the range filter has been converted to a function: 0|range(10) -> range(0, 10) + * the constant filter has been converted to a function: {{ some_date|date('DATE_W3C'|constant) }} -> {{ some_date|date(constant('DATE_W3C')) }} Changes: diff --git a/doc/templates.rst b/doc/templates.rst index ae156fc..07bbc09 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -1303,15 +1303,6 @@ the last filter applied to it. {{ var|raw }} {# var won't be escaped #} {% autoescape off %} -``constant`` (new in Twig 0.9.9) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -``constant`` returns the constant value for a given string: - -.. code-block:: jinja - - {{ some_date|date('DATE_W3C'|constant) }} - ``merge`` (new in Twig 0.9.10) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1456,6 +1447,15 @@ step of 1): {{ i }}, {% endfor %} +``constant`` +~~~~~~~~~~~~ + +``constant`` returns the constant value for a given string: + +.. code-block:: jinja + + {{ some_date|date(constant('DATE_W3C')) }} + Extensions ---------- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 0be6f31..faa77cf 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -57,7 +57,6 @@ class Twig_Extension_Core extends Twig_Extension 'upper' => new Twig_Filter_Function('strtoupper'), 'lower' => new Twig_Filter_Function('strtolower'), 'striptags' => new Twig_Filter_Function('strip_tags'), - 'constant' => new Twig_Filter_Function('constant'), // array helpers 'join' => new Twig_Filter_Function('twig_join_filter'), @@ -93,6 +92,7 @@ class Twig_Extension_Core extends Twig_Extension { return array( 'fn_range' => new Twig_Function($this, 'getRange'), + 'fn_constant' => new Twig_Function($this, 'getConstant'), ); } @@ -101,6 +101,11 @@ class Twig_Extension_Core extends Twig_Extension return range($start, $end, $step); } + public function getConstant($value) + { + return constant($value); + } + /** * Returns a list of filters to add to the existing list. * diff --git a/test/Twig/Tests/Fixtures/filters/constant.test b/test/Twig/Tests/Fixtures/functions/constant.test similarity index 87% rename from test/Twig/Tests/Fixtures/filters/constant.test rename to test/Twig/Tests/Fixtures/functions/constant.test index d630038..dbff4ab 100644 --- a/test/Twig/Tests/Fixtures/filters/constant.test +++ b/test/Twig/Tests/Fixtures/functions/constant.test @@ -1,7 +1,7 @@ --TEST-- "constant" filter --TEMPLATE-- -{{ date|date('DATE_W3C'|constant) }} +{{ date|date(constant('DATE_W3C')) }} --DATA-- $d = date_default_timezone_get(); date_default_timezone_set('UTC'); diff --git a/test/Twig/Tests/Fixtures/tags/include/only.test b/test/Twig/Tests/Fixtures/tags/include/only.test index 9f66ea6..3f9a6a8 100644 --- a/test/Twig/Tests/Fixtures/tags/include/only.test +++ b/test/Twig/Tests/Fixtures/tags/include/only.test @@ -10,7 +10,7 @@ --DATA-- return array('foo' => 'bar') --EXPECT-- -fn_range,foo,_parent, -fn_range,_parent, -fn_range,foo,foo1,_parent, -fn_range,foo1,_parent, +fn_range,fn_constant,foo,_parent, +fn_range,fn_constant,_parent, +fn_range,fn_constant,foo,foo1,_parent, +fn_range,fn_constant,foo1,_parent,