Class: Rack::Bug::TemplatesPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/templates_panel.rb,
lib/rack/bug/panels/templates_panel/trace.rb,
lib/rack/bug/panels/templates_panel/rendering.rb

Defined Under Namespace

Classes: Rendering, Trace

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #before, #call, #has_content?, #initialize, #panel_app, #render

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

This class inherits a constructor from Rack::Bug::Panel

Class Method Details

.record(template, &block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rack/bug/panels/templates_panel.rb', line 10

def self.record(template, &block)
  return block.call unless Rack::Bug.enabled?

  template_trace.start(template)
  result = block.call
  template_trace.finished(template)
  return result
end

.record_event(event) ⇒ Object



19
20
21
22
23
24
# File 'lib/rack/bug/panels/templates_panel.rb', line 19

def self.record_event(event)
  return unless Rack::Bug.enabled?

  template_description = "#{event.name}: #{event.payload[:virtual_path] || event.payload[:identifier]}"
  template_trace.add(template_description, event.time, event.end, event)
end

.resetObject



26
27
28
# File 'lib/rack/bug/panels/templates_panel.rb', line 26

def self.reset
  Thread.current["rack.bug.template_trace"] = Trace.new
end

.template_traceObject



30
31
32
# File 'lib/rack/bug/panels/templates_panel.rb', line 30

def self.template_trace
  Thread.current["rack.bug.template_trace"] ||= Trace.new
end

Instance Method Details

#contentObject



42
43
44
45
46
# File 'lib/rack/bug/panels/templates_panel.rb', line 42

def content
  result = render_template "panels/templates", :root_rendering => self.class.template_trace.root_rendering
  self.class.reset
  return result
end

#headingObject



38
39
40
# File 'lib/rack/bug/panels/templates_panel.rb', line 38

def heading
  "Templates: %.2fms" % (self.class.template_trace.total_time * 1_000)
end

#nameObject



34
35
36
# File 'lib/rack/bug/panels/templates_panel.rb', line 34

def name
  "templates"
end