mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Make it easy to set default resource limits.
This commit is contained in:
@@ -16,12 +16,14 @@ module Liquid
|
|||||||
attr_reader :scopes, :errors, :registers, :environments, :resource_limits
|
attr_reader :scopes, :errors, :registers, :environments, :resource_limits
|
||||||
attr_accessor :exception_handler
|
attr_accessor :exception_handler
|
||||||
|
|
||||||
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = {})
|
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil)
|
||||||
@environments = [environments].flatten
|
@environments = [environments].flatten
|
||||||
@scopes = [(outer_scope || {})]
|
@scopes = [(outer_scope || {})]
|
||||||
@registers = registers
|
@registers = registers
|
||||||
@errors = []
|
@errors = []
|
||||||
@resource_limits = (resource_limits || {}).merge!({ :render_score_current => 0, :assign_score_current => 0 })
|
@resource_limits = resource_limits || Template.default_resource_limits
|
||||||
|
@resource_limits[:render_score_current] = 0
|
||||||
|
@resource_limits[:assign_score_current] = 0
|
||||||
@parsed_expression = Hash.new{ |cache, markup| cache[markup] = Expression.parse(markup) }
|
@parsed_expression = Hash.new{ |cache, markup| cache[markup] = Expression.parse(markup) }
|
||||||
squash_instance_assigns_with_environments
|
squash_instance_assigns_with_environments
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ module Liquid
|
|||||||
Strainer.global_filter(mod)
|
Strainer.global_filter(mod)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_resource_limits
|
||||||
|
@default_resource_limits ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
# creates a new <tt>Template</tt> object from liquid source code
|
# creates a new <tt>Template</tt> object from liquid source code
|
||||||
# To enable profiling, pass in <tt>profile: true</tt> as an option.
|
# To enable profiling, pass in <tt>profile: true</tt> as an option.
|
||||||
# See Liquid::Profiler for more information
|
# See Liquid::Profiler for more information
|
||||||
@@ -95,9 +99,8 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# creates a new <tt>Template</tt> from an array of tokens. Use <tt>Template.parse</tt> instead
|
|
||||||
def initialize
|
def initialize
|
||||||
@resource_limits = {}
|
@resource_limits = self.class.default_resource_limits.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse source code.
|
# Parse source code.
|
||||||
|
|||||||
Reference in New Issue
Block a user