lib/rack/var_dump.rb in rack-var-dump-0.1.3 vs lib/rack/var_dump.rb in rack-var-dump-1.0.0
- old
+ new
@@ -1,21 +1,31 @@
require "rack/utils"
-require "rack/var_dump/object"
-require "rack/var_dump/version"
+require 'rack/var_dump/kernel'
+require 'rack/var_dump/version'
+require 'rack/var_dump/awesome_print'
module Rack
class VarDump
- include Object
-
@@var_aggregates = []
+ def self.reset!
+ @@var_aggregates = []
+ end
+
def self.var_dump(var, subject)
- @@var_aggregates << {:var => var.inspect, :subject => subject}
+ @@var_aggregates <<
+ { :var => ai(var, :html => true), :subject => subject }
end
- def self.reset!
- @@var_aggregates = []
+ def self.ai(var, options = {})
+ ap = AwesomePrint::Inspector.new(options)
+ ap.instance_eval do
+ formatter = AwesomePrint::VarDump.new(self)
+ instance_variable_set(:@formatter, formatter)
+ end
+
+ ap.awesome(var)
end
def initialize(app)
@app = app
end
@@ -28,23 +38,25 @@
body = ""
response.each {|org_body| body << org_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(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"
+ 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 << info[:var]
+ html << "\n\n"
+ end
+ html << "</pre></div>"
+
+ body.sub(/<body.*>/, '\&' + html)
end
- html << "</pre></div>"
- body.sub(/<body.*>/, '\&' + html)
- end
end
end