mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Add modulo filter
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user