mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Add modulo filter
This commit is contained in:
@@ -218,6 +218,10 @@ module Liquid
|
|||||||
to_number(input) / to_number(operand)
|
to_number(input) / to_number(operand)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def modulo(input, operand)
|
||||||
|
to_number(input) % to_number(operand)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def to_number(obj)
|
def to_number(obj)
|
||||||
|
|||||||
@@ -173,6 +173,10 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|||||||
assert_template_result "Liquid error: divided by 0", "{{ 5 | divided_by:0 }}"
|
assert_template_result "Liquid error: divided by 0", "{{ 5 | divided_by:0 }}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_modulo
|
||||||
|
assert_template_result "1", "{{ 3 | modulo:2 }}"
|
||||||
|
end
|
||||||
|
|
||||||
def test_append
|
def test_append
|
||||||
assigns = {'a' => 'bc', 'b' => 'd' }
|
assigns = {'a' => 'bc', 'b' => 'd' }
|
||||||
assert_template_result('bcd',"{{ a | append: 'd'}}",assigns)
|
assert_template_result('bcd',"{{ a | append: 'd'}}",assigns)
|
||||||
|
|||||||
Reference in New Issue
Block a user