lib/rack/var_dump.rb in rack-var-dump-0.1.2 vs lib/rack/var_dump.rb in rack-var-dump-0.1.3
- old
+ new
@@ -16,36 +16,35 @@
@@var_aggregates = []
end
def initialize(app)
@app = app
- VarDump.reset!
end
def call(env)
request = Rack::Request.new(env)
status, headers, response = @app.call(env)
- if /^text\/html/ =~ headers["Content-Type"] && !@@var_aggregates.empty?
+ if headers["Content-Type"] =~ /^text\/html/ && !@@var_aggregates.empty?
body = ""
response.each {|org_body| body << org_body}
- response = [apply(request, body)] if body =~ /<body.*>/
+ response = [apply(body)] if body =~ /<body.*>/
headers["Content-Length"] = response.join.bytesize.to_s
end
VarDump.reset!
[status, headers, response]
end
private
- def apply(request, response)
+ def apply(body)
html = '<div id="var_dump" style="display:block">'
html << '<pre style="background-color:#eee;padding:10px;font-size:11px;white-space:pre-wrap;color:black!important;">'
@@var_aggregates.each_with_index do |info, n|
html << "var_dump:#{n} #{info[:subject]}\n"
html << Rack::Utils.escape_html(info[:var])
html << "\n\n"
end
html << "</pre></div>"
- response.sub(/<body.*>/, '\&' + html)
+ body.sub(/<body.*>/, '\&' + html)
end
end
end