Module: AwesomePrintActionView

Defined in:
lib/ap/mixin/action_view.rb

Overview

Copyright © 2010-2011 Michael Dvorkin

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php


Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ap/mixin/action_view.rb', line 8

def self.included(base)
  unless base.const_defined?(:AP_ANSI_TO_HTML)
    hash = {} # Build ANSI => HTML color map.
    [ :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, :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)
  end
end

Instance Method Details

#ap_debug(object, options = {}) ⇒ Object Also known as: ap


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ap/mixin/action_view.rb', line 21

def ap_debug(object, options = {})
  formatted = h(object.ai(options))

  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>")
  end

  (:pre, formatted, :class => "debug_dump")
end