1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Final cleanup before 0.2.1 release

This commit is contained in:
Mike Dvorkin 2010-06-03 19:39:09 -07:00
parent bc0ca80936
commit fe58321517
3 changed files with 14 additions and 11 deletions

View file

@ -8,8 +8,8 @@ require File.dirname(__FILE__) + "/ap/core_ext/kernel"
require File.dirname(__FILE__) + "/ap/awesome_print"
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(::Logger) or defined?(::ActiveSupport::BufferedLogger)
require File.dirname(__FILE__) + "/ap/core_ext/action_view" if defined?(::ActionView)
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(::ActionView)
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(::ActiveRecord)
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(::ActiveSupport)

View file

@ -1,3 +1,8 @@
# Copyright (c) 2010 Michael Dvorkin
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module AwesomePrintActionView
def self.included(base)
@ -6,7 +11,7 @@ module AwesomePrintActionView
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
hash["\033[1;#{30+i}m"] = color
end
[ :black, :darkred, :darkgreen, :sienna, :navy, :darkmagenta, :darkcyan, :slategray ].each_with_index do |color, i|
[ :black, :darkred, :darkgreen, :brown, :navy, :darkmagenta, :darkcyan, :slategray ].each_with_index do |color, i|
hash["\033[0;#{30+i}m"] = color
end
base.const_set(:AP_ANSI_TO_HTML, hash.freeze)
@ -14,20 +19,18 @@ module AwesomePrintActionView
end
def ap_debug(object, options = {})
formatted = object.ai(options)
formatted = h(object.ai(options))
if options[:plain]
%Q|<pre class="debug_dump">#{h(formatted).gsub(" ", "&nbsp; ")}</pre>|
else
formatted = h(formatted).gsub(" ", "&nbsp; ")
unless options[:plain]
self.class::AP_ANSI_TO_HTML.each do |key, value|
formatted.gsub!(key, %Q|<font color="#{value}">|)
end
formatted.gsub!("\033[0m", "</font>")
%Q|<pre class="debug_dump">#{formatted}</pre>|
end
content_tag(:pre, formatted, :class => "debug_dump")
end
alias_method :ap, :ap_debug
end

View file

@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'action_view'
require 'ap/core_ext/action_view'
require 'ap/mixin/action_view'
describe "AwesomePrint ActionView extensions" do
before(:each) do
@ -15,7 +15,7 @@ describe "AwesomePrint ActionView extensions" do
it "should encode HTML entities" do
obj = " &<hello>"
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">&quot;&nbsp; &amp;&lt;hello&gt;&quot;</pre>'
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">&quot; &amp;&lt;hello&gt;&quot;</pre>'
end
it "should convert primary ANSI colors to HTML" do
@ -28,7 +28,7 @@ describe "AwesomePrint ActionView extensions" do
it "should convert mixed ANSI colors to HTML" do
obj = 42
[ :grayish, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :whiteish, :black, :pale ].zip(
[ :black, :darkred, :darkgreen, :sienna, :navy, :darkmagenta, :darkcyan, :slategray, :black, :slategray ]) do |ansi, html|
[ :black, :darkred, :darkgreen, :brown, :navy, :darkmagenta, :darkcyan, :slategray, :black, :slategray ]) do |ansi, html|
@view.ap(obj, :color => { :fixnum => ansi }).should == %Q|<pre class="debug_dump"><font color="#{html}">42</font></pre>|
end
end