add flatten filter

This commit is contained in:
Arthur Neves
2014-07-23 17:16:20 -04:00
parent 994f309465
commit 18e8ce1eb0
2 changed files with 16 additions and 1 deletions
+6 -1
View File
@@ -101,7 +101,7 @@ module Liquid
ary = InputIterator.new(input)
if property.nil?
ary.sort
elsif ary.first.respond_to?('[]'.freeze) and !ary.first[property].nil?
elsif ary.first.respond_to?('[]'.freeze) && !ary.first[property].nil?
ary.sort {|a,b| a[property] <=> b[property] }
elsif ary.first.respond_to?(property)
ary.sort {|a,b| a.send(property) <=> b.send(property) }
@@ -127,6 +127,11 @@ module Liquid
end
end
# flatten the given input
def flatten(input)
Array(input).flatten
end
# Replace occurrences of a string with another
def replace(input, string, replacement = ''.freeze)
input.to_s.gsub(string, replacement.to_s)