including unit test and documentation
--- /dev/null
+``abs``
+=======
+
+The ``abs`` filter returns the absolute value.
+
+.. code-block:: jinja
+
+ {# number = -5 #}
+
+ {{ number|abs }}
+
+ {# outputs 5 #}
+
+.. note::
+
+ Internally, Twig uses the PHP `abs`_ function.
+
+.. _`abs`: http://php.net/abs
'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)),
+ 'abs' => new Twig_Filter_Function('abs'),
// encoding
'url_encode' => new Twig_Filter_Function('twig_urlencode_filter'),
--- /dev/null
+--TEST--
+"abs" filter
+--TEMPLATE--
+{{ (-5.5)|abs }}
+{{ (-5)|abs }}
+{{ (-0)|abs }}
+{{ 0|abs }}
+{{ 5|abs }}
+{{ 5.5|abs }}
+{{ number1|abs }}
+{{ number2|abs }}
+{{ number3|abs }}
+{{ number4|abs }}
+{{ number5|abs }}
+{{ number6|abs }}
+--DATA--
+return array('number1' => -5.5, 'number2' => -5, 'number3' => -0, 'number4' => 0, 'number5' => 5, 'number6' => 5.5)
+--EXPECT--
+5.5
+5
+0
+0
+5
+5.5
+5.5
+5
+0
+0
+5
+5.5