Class: Rack::Bug::MustachePanel
- Inherits:
-
Panel
- Object
- Panel
- Rack::Bug::MustachePanel
- Defined in:
- lib/rack/bug/panels/mustache_panel.rb
Overview
MustachePanel is a Rack::Bug panel which tracks the time spent rendering Mustache views as well as all the variables accessed during view rendering.
It can be used to track down slow partials and ensure you’re only generating data you need.
Also, it’s fun.
Defined Under Namespace
Classes: View
Class Method Summary collapse
-
.reset ⇒ Object
Clear out our page load-specific variables.
-
.times ⇒ Object
The view render times for this page load.
-
.variables ⇒ Object
The variables used on this page load.
Instance Method Summary collapse
-
#content ⇒ Object
The content of our Rack::Bug panel.
-
#heading ⇒ Object
The string used for our tab in Rack::Bug’s navigation bar.
-
#name ⇒ Object
The name of this Rack::Bug panel.
Class Method Details
.reset ⇒ Object
Clear out our page load-specific variables.
46 47 48 49 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 46 def self.reset Thread.current["rack.bug.mustache.times"] = {} Thread.current["rack.bug.mustache.vars"] = {} end |
.times ⇒ Object
The view render times for this page load
52 53 54 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 52 def self.times Thread.current["rack.bug.mustache.times"] ||= {} end |
.variables ⇒ Object
The variables used on this page load
57 58 59 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 57 def self.variables Thread.current["rack.bug.mustache.vars"] ||= {} end |
Instance Method Details
#content ⇒ Object
The content of our Rack::Bug panel
74 75 76 77 78 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 74 def content View.render ensure self.class.reset end |
#heading ⇒ Object
The string used for our tab in Rack::Bug’s navigation bar
67 68 69 70 71 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 67 def heading "{{%.2fms}}" % self.class.times.values.inject(0.0) do |sum, obj| sum + obj end end |
#name ⇒ Object
The name of this Rack::Bug panel
62 63 64 |
# File 'lib/rack/bug/panels/mustache_panel.rb', line 62 def name "mustache" end |