mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Added support for setting custom defaults in ~/.aprc
This commit is contained in:
parent
7fe38425a5
commit
936d73e6e9
5 changed files with 64 additions and 6 deletions
15
CHANGELOG
Normal file
15
CHANGELOG
Normal file
|
@ -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.
|
||||||
|
|
14
README.md
14
README.md
|
@ -144,9 +144,19 @@ Supported color names:
|
||||||
}
|
}
|
||||||
rails>
|
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 ###
|
### Note on Patches/Pull Requests ###
|
||||||
* Fork the project on Github.
|
* Fork the project on Github.
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.1.2
|
0.1.3
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{awesome_print}
|
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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Michael Dvorkin"]
|
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.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.email = %q{mike@dvorkin.net}
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = [
|
||||||
|
@ -17,7 +17,8 @@ Gem::Specification.new do |s|
|
||||||
"README.md"
|
"README.md"
|
||||||
]
|
]
|
||||||
s.files = [
|
s.files = [
|
||||||
"LICENSE",
|
"CHANGELOG",
|
||||||
|
"LICENSE",
|
||||||
"README.md",
|
"README.md",
|
||||||
"Rakefile",
|
"Rakefile",
|
||||||
"VERSION",
|
"VERSION",
|
||||||
|
|
|
@ -29,6 +29,8 @@ class AwesomePrint
|
||||||
}.merge(options.delete(:color) || {})
|
}.merge(options.delete(:color) || {})
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
|
|
||||||
|
load_custom_defaults
|
||||||
|
|
||||||
@indentation = @options[:indent].abs
|
@indentation = @options[:indent].abs
|
||||||
Thread.current[AP] ||= []
|
Thread.current[AP] ||= []
|
||||||
end
|
end
|
||||||
|
@ -196,4 +198,34 @@ class AwesomePrint
|
||||||
@outdent = ' ' * (@indentation - @options[:indent].abs)
|
@outdent = ' ' * (@indentation - @options[:indent].abs)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue