Add modulo filter

This commit is contained in:
Jonathan Rudenberg
2011-11-17 14:08:57 -05:00
parent 745d875e79
commit c4d713b6bb
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -218,6 +218,10 @@ module Liquid
to_number(input) / to_number(operand)
end
def modulo(input, operand)
to_number(input) % to_number(operand)
end
private
def to_number(obj)
+4
View File
@@ -173,6 +173,10 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_template_result "Liquid error: divided by 0", "{{ 5 | divided_by:0 }}"
end
def test_modulo
assert_template_result "1", "{{ 3 | modulo:2 }}"
end
def test_append
assigns = {'a' => 'bc', 'b' => 'd' }
assert_template_result('bcd',"{{ a | append: 'd'}}",assigns)