# File lib/awesome_print/formatter.rb, line 15 def initialize(inspector) @inspector = inspector @options = inspector.options @indentation = @options[:indent].abs end
Hook this when adding custom formatters. Check out lib/awesome_print/ext directory for custom formatters that ship with awesome_print.
# File lib/awesome_print/formatter.rb, line 36 def cast(object, type) CORE.grep(type)[0] || :self end
Pick the color and apply it to the given string as necessary.
# File lib/awesome_print/formatter.rb, line 42 def colorize(s, type) s = CGI.escapeHTML(s) if @options[:html] if @options[:plain] || !@options[:color][type] || !@inspector.colorize? s else s.send(@options[:color][type], @options[:html]) end end
Main entry point to format an object.
# File lib/awesome_print/formatter.rb, line 23 def format(object, type = nil) core_class = cast(object, type) awesome = if core_class != :self send(:"awesome_#{core_class}", object) # Core formatters. else awesome_self(object, type) # Catch all that falls back to object.inspect. end @options[:html] ? "<pre>#{awesome}</pre>" : awesome end