mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Merge pull request #117 from mikemcquaid/fix-html-printing
Fix HTML printing.
This commit is contained in:
commit
28c9577cb4
3 changed files with 21 additions and 5 deletions
|
@ -7,7 +7,12 @@ module Kernel
|
|||
|
||||
def ai(options = {})
|
||||
ap = AwesomePrint::Inspector.new(options)
|
||||
ap.awesome self
|
||||
awesome = ap.awesome self
|
||||
if options[:html]
|
||||
awesome = "<pre>#{awesome}</pre>"
|
||||
awesome = awesome.html_safe if defined? ActiveSupport
|
||||
end
|
||||
awesome
|
||||
end
|
||||
alias :awesome_inspect :ai
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module AwesomePrint
|
|||
else
|
||||
awesome_self(object, type) # Catch all that falls back to object.inspect.
|
||||
end
|
||||
@options[:html] ? "<pre>#{awesome}</pre>" : awesome
|
||||
awesome
|
||||
end
|
||||
|
||||
# Hook this when adding custom formatters. Check out lib/awesome_print/ext
|
||||
|
|
|
@ -74,13 +74,24 @@ describe "AwesomePrint" do
|
|||
markup = [ 1, :two, "three" ]
|
||||
markup.ai(:html => true).should == <<-EOS.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd><pre><kbd style="color:blue">1</kbd></pre>,
|
||||
<kbd style="color:white">[1] </kbd><pre><kbd style="color:darkcyan">:two</kbd></pre>,
|
||||
<kbd style="color:white">[2] </kbd><pre><kbd style="color:brown">"three"</kbd></pre>
|
||||
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
||||
<kbd style="color:white">[1] </kbd><kbd style="color:darkcyan">:two</kbd>,
|
||||
<kbd style="color:white">[2] </kbd><kbd style="color:brown">"three"</kbd>
|
||||
]</pre>
|
||||
EOS
|
||||
end
|
||||
|
||||
it "wraps hash ap output with only an outer <pre> tag" do
|
||||
markup = [ { "hello" => "world" } ]
|
||||
markup.ai(:html => true).should == <<-EOS.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd>{
|
||||
"hello"<kbd style="color:slategray"> => </kbd><kbd style="color:brown">"world"</kbd>
|
||||
}
|
||||
]</pre>
|
||||
EOS
|
||||
end
|
||||
|
||||
it "encodes HTML entities (plain)" do
|
||||
markup = ' &<hello>'
|
||||
markup.ai(:html => true, :plain => true).should == '<pre>" &<hello>"</pre>'
|
||||
|
|
Loading…
Reference in a new issue