Class: Rack::DevBar

Inherits:
Object
  • Object
show all
Defined in:
lib/devbar.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DevBar

Returns a new instance of DevBar.



5
6
7
# File 'lib/devbar.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#barObject



29
30
31
# File 'lib/devbar.rb', line 29

def bar
  %(<div style="height:24px;width:100%;font-size:12px;font-family:helvetica,arial;background-color:red;bottom:0;position:fixed;right:0; text-align:center;color:white;z-index:999;opacity:0.7;line-height:24px;font-weight:bold;" onmouseover="if(this.style.bottom=='0px'){this.style.top=0;this.style.bottom=null}else{this.style.bottom=0;this.style.top=null}">#{ Rails.env.upcase } ENVIRONMENT</div>)
end

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/devbar.rb', line 9

def call(env)
  status, headers, body  = @app.call(env)

  if body && body.respond_to?(:each)
    body.each do |part|
      if part =~ /<\/body>/
        part.sub!(/<\/body>/, "#{bar}</body>")

        if headers['Content-Length']
          headers['Content-Length'] = (headers['Content-Length'].to_i + bar.length).to_s
        end

        break
      end
    end
  end

  [status, headers, body]
end