diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..6053820 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,15 @@ +0.1.3 + - Added support for setting custom defaults in ~/.aprc + +0.1.2 + - Correctly handle empty arrays and hashes + - Use alias_method instead of alias (fixes non-tty method aliasing) + - Added awesome_inspect method + +0.1.1 + - Added support for tableless ActiveRecord models + - Left align hash keys if @options[:indent] is negative + +0.1.0 + - Initial Release. + \ No newline at end of file diff --git a/README.md b/README.md index 251ed14..3adc2d9 100644 --- a/README.md +++ b/README.md @@ -144,9 +144,19 @@ Supported color names: } rails> -### Known Issues ### +### 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``. +For example: -* Windows... + # ~/.aprc file. + AwesomePrint.defaults = { + :indent => -2, + :color => { + :hash => :pale, + :class => :white + } + } ### Note on Patches/Pull Requests ### * Fork the project on Github. diff --git a/VERSION b/VERSION index d917d3e..b1e80bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 +0.1.3 diff --git a/awesome_print.gemspec b/awesome_print.gemspec index 9262a24..c8616f1 100644 --- a/awesome_print.gemspec +++ b/awesome_print.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{awesome_print} - s.version = "0.1.2" + s.version = "0.1.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Michael Dvorkin"] - s.date = %q{2010-04-05} + s.date = %q{2010-04-07} s.description = %q{Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports Rails ActiveRecord objects via included mixin.} s.email = %q{mike@dvorkin.net} s.extra_rdoc_files = [ @@ -17,7 +17,8 @@ Gem::Specification.new do |s| "README.md" ] s.files = [ - "LICENSE", + "CHANGELOG", + "LICENSE", "README.md", "Rakefile", "VERSION", diff --git a/lib/ap/awesome_print.rb b/lib/ap/awesome_print.rb index f5efe1a..3f395f2 100755 --- a/lib/ap/awesome_print.rb +++ b/lib/ap/awesome_print.rb @@ -29,6 +29,8 @@ class AwesomePrint }.merge(options.delete(:color) || {}) }.merge(options) + load_custom_defaults + @indentation = @options[:indent].abs Thread.current[AP] ||= [] end @@ -196,4 +198,34 @@ class AwesomePrint @outdent = ' ' * (@indentation - @options[:indent].abs) end + # Load ~/.aprc file that can store custom defaults, for example: + # + # AwesomePrint.defaults = { + # :indent => -2, + # :color => { + # :trueclass => :red + # } + # } + #------------------------------------------------------------------------------ + def load_custom_defaults + dotfile = File.join(ENV["HOME"], ".aprc") + if File.readable?(dotfile) + load dotfile + @options[:color].merge!(self.class.defaults.delete(:color) || {}) + @options.merge!(self.class.defaults) + end + rescue => e + $stderr.puts "Could not load #{dotfile}: #{e}" + end + + # Class accessors for custom defaults. + #------------------------------------------------------------------------------ + def self.defaults + @@defaults ||= {} + end + + def self.defaults=(*args) + @@defaults = *args + end + end