Add reverse filter

This commit is contained in:
Jay Strybis
2013-03-07 16:29:39 -06:00
parent f7d1e1d0c1
commit a556ae6c26
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -90,6 +90,12 @@ module Liquid
end
end
# Reverse the elements of an array
def reverse(input)
ary = [input].flatten
ary.reverse
end
# map/collect on a given property
def map(input, property)
ary = [input].flatten
+4
View File
@@ -80,6 +80,10 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal [{"a" => 1}, {"a" => 2}, {"a" => 3}, {"a" => 4}], @filters.sort([{"a" => 4}, {"a" => 3}, {"a" => 1}, {"a" => 2}], "a")
end
def test_reverse
assert_equal [4,3,2,1], @filters.reverse([1,2,3,4])
end
def test_map
assert_equal [1,2,3,4], @filters.map([{"a" => 1}, {"a" => 2}, {"a" => 3}, {"a" => 4}], 'a')
assert_template_result 'abc', "{{ ary | map:'foo' | map:'bar' }}",