lib/liquid/profiler/hooks.rb in liquid-4.0.4 vs lib/liquid/profiler/hooks.rb in liquid-5.0.0

- old
+ new

@@ -1,23 +1,35 @@ +# frozen_string_literal: true + module Liquid - class BlockBody - def render_node_with_profiling(node, output, context, skip_output = false) - Profiler.profile_node_render(node) do - render_node_without_profiling(node, output, context, skip_output) + module BlockBodyProfilingHook + def render_node(context, output, node) + if (profiler = context.profiler) + profiler.profile_node(context.template_name, code: node.raw, line_number: node.line_number) do + super + end + else + super end end - - alias_method :render_node_without_profiling, :render_node_to_output - alias_method :render_node_to_output, :render_node_with_profiling end + BlockBody.prepend(BlockBodyProfilingHook) - class Include < Tag - def render_with_profiling(context) - Profiler.profile_children(context.evaluate(@template_name_expr).to_s) do - render_without_profiling(context) - end + module DocumentProfilingHook + def render_to_output_buffer(context, output) + return super unless context.profiler + context.profiler.profile(context.template_name) { super } end + end + Document.prepend(DocumentProfilingHook) - alias_method :render_without_profiling, :render - alias_method :render, :render_with_profiling + module ContextProfilingHook + attr_accessor :profiler + + def new_isolated_subcontext + new_context = super + new_context.profiler = profiler + new_context + end end + Context.prepend(ContextProfilingHook) end