class Rack::Showme
Constants
- VERSION
Public Class Methods
new(app)
click to toggle source
# File lib/rack/showme.rb, line 7 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/showme.rb, line 11 def call(env) @env = env @status, @headers, @response = @app.call(env) inject_html if initial_page_request? [@status, @headers, @response] end
Private Instance Methods
ajax_request?()
click to toggle source
# File lib/rack/showme.rb, line 21 def ajax_request? @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" end
css_line()
click to toggle source
# File lib/rack/showme.rb, line 50 def css_line files = ["showme.css"] files << "showme.breakpoints.css" if display_breakpoints? %Q{<style type="text/css">#{files.map{|file| read_public_file(file) }.join()}</style>\n} end
display_breakpoints?()
click to toggle source
# File lib/rack/showme.rb, line 37 def display_breakpoints? @display_breakpoints ||= !!Options.show_breakpoints end
html_response?()
click to toggle source
# File lib/rack/showme.rb, line 33 def html_response? @headers && @headers["Content-Type"] && @headers["Content-Type"].include?("text/html") end
initial_page_request?()
click to toggle source
# File lib/rack/showme.rb, line 29 def initial_page_request? !ajax_request? && html_response? && response_compatible? end
inject_html()
click to toggle source
# File lib/rack/showme.rb, line 41 def inject_html body = @response.body body.gsub!("</body>", "#{css_line}</body>") body.gsub!("<body>", "<body>#{show_boxes}") @response.body = body @headers["Content-Length"] = @response.body.bytesize.to_s end
read_public_file(filename)
click to toggle source
# File lib/rack/showme.rb, line 62 def read_public_file(filename) output = ::File.open(::File.join(::File.dirname(__FILE__), "showme", "public", filename), "r:UTF-8") do |f| f.read end end
response_compatible?()
click to toggle source
# File lib/rack/showme.rb, line 25 def response_compatible? @response.respond_to?(:body) end
show_boxes()
click to toggle source
# File lib/rack/showme.rb, line 56 def show_boxes html_string = MessageBox.new(Options).html html_string += BreakpointsBox.new(Options).html if display_breakpoints? html_string end