lib/rack/insight/panels/templates_panel.rb in rack-insight-0.5.16 vs lib/rack/insight/panels/templates_panel.rb in rack-insight-0.5.17

- old
+ new

@@ -1,45 +1,49 @@ module Rack::Insight - class TemplatesPanel < Panel - require "rack/insight/panels/templates_panel/rendering" + require "rack/insight/panels/templates_panel/stats" - def initialize(app) - super - - @current = nil - end - - def request_start(env, start) - @current = Rendering.new("root") + @stats = Rack::Insight::TemplatesPanel::Stats.new("root") end def request_finish(env, status, headers, body, timing) - store(env, @current) - @current = nil + @stats.finish! + store(env, @stats) + @stats = nil end def before_detect(method_call, args) template_name = method_call.object.virtual_path - rendering = Rendering.new(template_name) - @current.add(rendering) - @current = rendering + @stats.begin_record!(rendering) end def after_detect(method_call, timing, args, result) - @current.timing = timing - @current = @current.parent + @stats.finish_record!(timing.duration) end def heading_for_request(number) - "Templates: %.2fms" % (retrieve(number).inject(0.0){|memo, rendering| memo + rendering.duration}) + "Templates: #{heading_time(number)}" end + def heading_time(number) + stat = retrieve(number).first + if stat.respond_to?(:root) + if stat.root.respond_to?(:_human_time) + stat.root._human_time + end + end + end + def content_for_request(number) - render_template "panels/templates", :root_rendering => retrieve(number).first + stat = retrieve(number).first + rendering_root = stat.root if stat.respond_to?(:root) + if rendering_root + render_template 'magic_panel', :magic_insights => rendering_root.children, :name => "Templates: #{(rendering_root._human_time)}" + else + render_template 'no_data', :name => self.camelized_name + end end end - end