1
0
Fork 0
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:
Michael Dvorkin 2013-06-17 21:00:43 -07:00
commit 28c9577cb4
3 changed files with 21 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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">&quot;three&quot;</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">&quot;three&quot;</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>{
&quot;hello&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;world&quot;</kbd>
}
]</pre>
EOS
end
it "encodes HTML entities (plain)" do
markup = ' &<hello>'
markup.ai(:html => true, :plain => true).should == '<pre>&quot; &amp;&lt;hello&gt;&quot;</pre>'