Class: Rack::Bug::MustachePanel

Inherits:
Panel
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.resetObject

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

.timesObject

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

.variablesObject

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

#contentObject

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

#headingObject

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

#nameObject

The name of this Rack::Bug panel



62
63
64
# File 'lib/rack/bug/panels/mustache_panel.rb', line 62

def name
  "mustache"
end