mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
Use node to refer to objects from the nodelist rather than token.
This commit is contained in:
@@ -84,10 +84,10 @@ module Liquid
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
token_output = render_token(token, context)
|
node_output = render_node(token, context)
|
||||||
|
|
||||||
unless token.is_a?(Block) && token.blank?
|
unless token.is_a?(Block) && token.blank?
|
||||||
output << token_output
|
output << node_output
|
||||||
end
|
end
|
||||||
rescue MemoryError => e
|
rescue MemoryError => e
|
||||||
raise e
|
raise e
|
||||||
@@ -101,15 +101,15 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_token(token, context)
|
def render_node(node, context)
|
||||||
token_output = (token.respond_to?(:render) ? token.render(context) : token)
|
node_output = (node.respond_to?(:render) ? node.render(context) : node)
|
||||||
token_str = token_output.is_a?(Array) ? token_output.join : token_output.to_s
|
node_output = node_output.is_a?(Array) ? node_output.join : node_output.to_s
|
||||||
|
|
||||||
context.resource_limits.render_length += token_str.length
|
context.resource_limits.render_length += node_output.length
|
||||||
if context.resource_limits.reached?
|
if context.resource_limits.reached?
|
||||||
raise MemoryError.new("Memory limits exceeded".freeze)
|
raise MemoryError.new("Memory limits exceeded".freeze)
|
||||||
end
|
end
|
||||||
token_str
|
node_output
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_variable(token, options)
|
def create_variable(token, options)
|
||||||
|
|||||||
+13
-13
@@ -19,7 +19,7 @@ module Liquid
|
|||||||
# inside of <tt>{% include %}</tt> tags.
|
# inside of <tt>{% include %}</tt> tags.
|
||||||
#
|
#
|
||||||
# profile.each do |node|
|
# profile.each do |node|
|
||||||
# # Access to the token itself
|
# # Access to the node itself
|
||||||
# node.code
|
# node.code
|
||||||
#
|
#
|
||||||
# # Which template and line number of this node.
|
# # Which template and line number of this node.
|
||||||
@@ -46,15 +46,15 @@ module Liquid
|
|||||||
class Timing
|
class Timing
|
||||||
attr_reader :code, :partial, :line_number, :children
|
attr_reader :code, :partial, :line_number, :children
|
||||||
|
|
||||||
def initialize(token, partial)
|
def initialize(node, partial)
|
||||||
@code = token.respond_to?(:raw) ? token.raw : token
|
@code = node.respond_to?(:raw) ? node.raw : node
|
||||||
@partial = partial
|
@partial = partial
|
||||||
@line_number = token.respond_to?(:line_number) ? token.line_number : nil
|
@line_number = node.respond_to?(:line_number) ? node.line_number : nil
|
||||||
@children = []
|
@children = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start(token, partial)
|
def self.start(node, partial)
|
||||||
new(token, partial).tap(&:start)
|
new(node, partial).tap(&:start)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@@ -70,11 +70,11 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.profile_token_render(token)
|
def self.profile_node_render(node)
|
||||||
if Profiler.current_profile && token.respond_to?(:render)
|
if Profiler.current_profile && node.respond_to?(:render)
|
||||||
Profiler.current_profile.start_token(token)
|
Profiler.current_profile.start_node(node)
|
||||||
output = yield
|
output = yield
|
||||||
Profiler.current_profile.end_token(token)
|
Profiler.current_profile.end_node(node)
|
||||||
output
|
output
|
||||||
else
|
else
|
||||||
yield
|
yield
|
||||||
@@ -132,11 +132,11 @@ module Liquid
|
|||||||
@root_timing.children.length
|
@root_timing.children.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_token(token)
|
def start_node(node)
|
||||||
@timing_stack.push(Timing.start(token, current_partial))
|
@timing_stack.push(Timing.start(node, current_partial))
|
||||||
end
|
end
|
||||||
|
|
||||||
def end_token(_token)
|
def end_node(_node)
|
||||||
timing = @timing_stack.pop
|
timing = @timing_stack.pop
|
||||||
timing.finish
|
timing.finish
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class BlockBody
|
class BlockBody
|
||||||
def render_token_with_profiling(token, context)
|
def render_node_with_profiling(node, context)
|
||||||
Profiler.profile_token_render(token) do
|
Profiler.profile_node_render(node) do
|
||||||
render_token_without_profiling(token, context)
|
render_node_without_profiling(node, context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :render_token_without_profiling, :render_token
|
alias_method :render_node_without_profiling, :render_node
|
||||||
alias_method :render_token, :render_token_with_profiling
|
alias_method :render_node, :render_node_with_profiling
|
||||||
end
|
end
|
||||||
|
|
||||||
class Include < Tag
|
class Include < Tag
|
||||||
|
|||||||
Reference in New Issue
Block a user