mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 19:30:47 -07:00
Take nested values into account for assign score
This commit is contained in:
@@ -23,16 +23,25 @@ module Liquid
|
|||||||
def render(context)
|
def render(context)
|
||||||
val = @from.render(context)
|
val = @from.render(context)
|
||||||
context.scopes.last[@to] = val
|
context.scopes.last[@to] = val
|
||||||
|
context.resource_limits.assign_score += assign_score_of(val)
|
||||||
inc = val.instance_of?(String) || val.instance_of?(Array) || val.instance_of?(Hash) ? val.length : 1
|
|
||||||
context.resource_limits.assign_score += inc
|
|
||||||
|
|
||||||
''.freeze
|
''.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assign_score_of(val)
|
||||||
|
if val.instance_of?(String)
|
||||||
|
val.length
|
||||||
|
elsif val.instance_of?(Array) || val.instance_of?(Hash)
|
||||||
|
val.reduce(0) { |n, child| n + assign_score_of(child) }
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('assign'.freeze, Assign)
|
Template.register_tag('assign'.freeze, Assign)
|
||||||
|
|||||||
Reference in New Issue
Block a user