awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.08k stars 454 forks source link

ActionView ap and ap_debug displays as string instead of HTML (with proposed patch) #199

Open JohnAtFenestra opened 9 years ago

JohnAtFenestra commented 9 years ago

Applies to:

awesome_print (1.6.1)
rails (4.2.1)

Adding the following for debugging purposes in a view:

<%= ap params %>

displays the text as a string without any formatting.

<pre class="debug_dump">{ &quot;controller&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;devise/sessions&quot;</kbd>, &quot;action&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;new&quot;</kbd> }</pre>

After researching the issue, I discovered the problem is in lib/awesome_print/ext/action_view.rb. If we make the following change to ap_debug, the view properly displays the output properly formatted as HTML.

    def ap_debug(object, options = {})
      # Addition of ::ActiveSupport::SafeBuffer.new by JE on 2015-07-21
      ::ActiveSupport::SafeBuffer.new object.ai(options.merge(:html => true)).sub(/^<pre([\s>])/, '<pre class="debug_dump"\\1')
    end
IslamAzab commented 9 years ago

I get something similar, any luck with finding a fix for it ?

gerrywastaken commented 8 years ago

@IslamAzab: @JohnAtFenestra has already shown how it can be fixed but the change was never made to this library. I'm guessing this is because the change will only work with later versions of rails and might break for previous versions (just a guess).

It seems the author of awesome_print was creating version 2, but that hasn't been worked on since 2015, so things are now at the point where you or somebody else should probably apply the patch yourself to a fork.

IslamAzab commented 8 years ago

@gerrywastaken Thanks.

flynfish commented 8 years ago

Would be nice to include this in an updated version

flynfish commented 8 years ago

You can also just call html_safe on it:

<%= (ap @model).html_safe %>
gerrywastaken commented 8 years ago

@flynfish There are 15 pull requests and the last commit was March of 2015. I'm guessing @michaeldv has more important things to work on. So I suspect it's at a stage of fork, or live with it.

michaeldv commented 8 years ago

@gerrywastaken It's not so simple as I work for the fruit company. I would be happy to provide commit/push rights to you or anyone interested. Let me know.

gerrywastaken commented 8 years ago

@michaeldv Makes sense. I wasn't complaining btw, I completely understand about having limited time. Having said that.... OK, if you give me rights I'll pitch in when I have free time.

IslamAzab commented 8 years ago

@michaeldv Let me know what I can help with too, I am interested.

michaeldv commented 8 years ago

@IslamAzab Added you to https://github.com/michaeldv/awesome_print/settings/collaboration as well, please coordinate new version release with the folks there.

gerrywastaken commented 8 years ago

@michaeldv Thanks for adding me. I'm am unable to access that page and just get back a 404.

BTW, if anybody wants to submit a pull request for this issue, please go ahead. :)