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

Shell escape file and directory names, README updates

This commit is contained in:
Mike Dvorkin 2010-05-05 21:30:00 -07:00
parent 40494e62df
commit d2017f66c5
3 changed files with 28 additions and 4 deletions

View file

@ -1,3 +1,8 @@
0.2.0
- Added support for logger.ap (including Rails logger)
- ap now works with scripts that use ActiveRecord/ActiveSupport outside Rails
- ap now correctly shows file and directory names with fancy characters (shell escape)
0.1.4
- Format BigDecimal and Rational objects as Float scalars
- Explicit options parameter can override custom defaults

View file

@ -144,6 +144,18 @@ Supported color names:
}
rails>
### IRB integration ###
To use awesome_print as default formatter in irb and Rails console add the following
lines into your ~/.irbrc file:
require "rubygems"
require "ap"
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
### Logger Convenience Method ###
awesome_print adds an ap method to the Logger and ActiveSupport::BufferedLogger classes,
allowing you to call:
@ -158,7 +170,6 @@ in the custom defaults (see below), or you can override on a per call basis with
logger.ap object, :warn
### Setting Custom Defaults ###
You can set your own default options by creating ``.aprc`` file in your home
directory. Within that file assign your defaults to ``AwesomePrint.defaults``.
@ -180,8 +191,14 @@ For example:
* Commit, do not mess with rakefile, version, or history.
* Send me a pull request.
### Contributors ###
* Daniel Bretoi -- http://github.com/danielb2
* eregon -- http://github.com/eregon
* Tobias Crawley -- http://github.com/tobias
### License ###
Copyright (c) 2010 Michael Dvorkin
%w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
Released under the MIT license. See LICENSE file for details.
Released under the MIT license. See LICENSE file for details.

View file

@ -3,6 +3,8 @@
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require "shellwords"
class AwesomePrint
AP = :__awesome_print__
CORE = [ :array, :hash, :class, :file, :dir, :bigdecimal, :rational ]
@ -103,14 +105,14 @@ class AwesomePrint
# Format File object.
#------------------------------------------------------------------------------
def awesome_file(f)
ls = File.directory?(f) ? `ls -adlF #{f.path}` : `ls -alF #{f.path}`
ls = File.directory?(f) ? `ls -adlF #{f.path.shellescape}` : `ls -alF #{f.path.shellescape}`
awesome_self(f, :with => ls.empty? ? nil : "\n#{ls.chop}")
end
# Format Dir object.
#------------------------------------------------------------------------------
def awesome_dir(d)
ls = `ls -alF #{d.path}`
ls = `ls -alF #{d.path.shellescape}`
awesome_self(d, :with => ls.empty? ? nil : "\n#{ls.chop}")
end