Fix uniq filter with string input

This commit is contained in:
Florian Weingarten
2015-06-04 22:55:03 -04:00
parent 13716fa68b
commit 1e23036b2d
3 changed files with 14 additions and 7 deletions
+9 -3
View File
@@ -138,10 +138,12 @@ module Liquid
# Remove duplicate elements from an array
# provide optional property with which to determine uniqueness
def uniq(input, property = nil)
ary = InputIterator.new(input)
if property.nil?
input.uniq
elsif input.first.respond_to?(:[])
input.uniq{ |a| a[property] }
ary.uniq
elsif ary.first.respond_to?(:[])
ary.uniq{ |a| a[property] }
end
end
@@ -391,6 +393,10 @@ module Liquid
reverse_each.to_a
end
def uniq(&block)
to_a.uniq(&block)
end
def each
@input.each do |e|
yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)