mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Ensure sum filter calls to_liquid
This commit is contained in:
@@ -878,19 +878,22 @@ module Liquid
|
||||
# @liquid_return [number]
|
||||
def sum(input, property = nil)
|
||||
ary = InputIterator.new(input, context)
|
||||
return 0 if ary.empty?
|
||||
|
||||
if ary.empty?
|
||||
0
|
||||
elsif property.nil?
|
||||
ary.sum do |item|
|
||||
Utils.to_number(item)
|
||||
end
|
||||
else
|
||||
ary.sum do |item|
|
||||
item.respond_to?(:[]) ? Utils.to_number(item[property]) : 0
|
||||
rescue TypeError
|
||||
raise_property_error(property)
|
||||
values_for_sum = ary.map do |item|
|
||||
if property.nil?
|
||||
item
|
||||
elsif item.respond_to?(:[])
|
||||
item[property]
|
||||
else
|
||||
0
|
||||
end
|
||||
rescue TypeError
|
||||
raise_property_error(property)
|
||||
end
|
||||
|
||||
InputIterator.new(values_for_sum, context).sum do |item|
|
||||
Utils.to_number(item)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user