From: Fabien Potencier Date: Wed, 28 Dec 2011 19:34:32 +0000 (+0100) Subject: tweaked previous merge X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=88de457774f827b1d36880eaf13cd9e1de13e980;p=web%2Fkonrad%2Ftwig.git tweaked previous merge --- diff --git a/CHANGELOG b/CHANGELOG index b75a347..a53f805 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* 1.5.0-RC2 + + * added a number_format filter + * 1.5.0-RC1 (2011-12-26) * removed the need to quote hash keys diff --git a/doc/filters/number_format.rst b/doc/filters/number_format.rst index 8b5f90b..ccc8f2f 100644 --- a/doc/filters/number_format.rst +++ b/doc/filters/number_format.rst @@ -1,8 +1,8 @@ ``number_format`` ================= -.. versionadded:: 1.6 - The number_format filter was added in Twig 1.6 +.. versionadded:: 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: @@ -36,4 +36,3 @@ The defaults set for ``number_format`` can be over-ridden upon each call using t additional parameters. .. _`number_format`: http://php.net/number_format - diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index e247c95..126ff97 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -93,10 +93,10 @@ class Twig_Extension_Core extends Twig_Extension { $filters = array( // formatting filters - 'date' => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)), - 'format' => new Twig_Filter_Function('sprintf'), - 'replace' => new Twig_Filter_Function('strtr'), - 'number_format' => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)), + 'date' => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)), + 'format' => new Twig_Filter_Function('sprintf'), + 'replace' => new Twig_Filter_Function('strtr'), + 'number_format' => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)), // encoding 'url_encode' => new Twig_Filter_Function('twig_urlencode_filter'), @@ -352,15 +352,18 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $ function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) { $defaults = $env->getExtension('core')->getNumberFormat(); - if ($decimal === null) { + if (null === $decimal) { $decimal = $defaults[0]; } - if ($decimalPoint === null) { + + if (null === $decimalPoint) { $decimalPoint = $defaults[1]; } - if ($thousandSep === null) { + + if (null === $thousandSep) { $thousandSep = $defaults[2]; } + return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); }