hirb 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION.yml +1 -1
- data/lib/hirb/formatter.rb +1 -1
- data/lib/hirb/view.rb +28 -10
- data/test/formatter_test.rb +5 -3
- data/test/view_test.rb +7 -0
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/VERSION.yml
CHANGED
data/lib/hirb/formatter.rb
CHANGED
@@ -175,7 +175,7 @@ module Hirb
|
|
175
175
|
@klass_config[output_class] ||= begin
|
176
176
|
output_ancestors_with_config = output_class.ancestors.map {|e| e.to_s}.select {|e| @config.has_key?(e)}
|
177
177
|
@klass_config[output_class] = output_ancestors_with_config.reverse.inject({}) {|h, klass|
|
178
|
-
(klass == output_class.to_s || @config[klass][:ancestor]) ?
|
178
|
+
(klass == output_class.to_s || @config[klass][:ancestor]) ? Util.recursive_hash_merge(h, @config[klass]) : h
|
179
179
|
}
|
180
180
|
end
|
181
181
|
end
|
data/lib/hirb/view.rb
CHANGED
@@ -14,25 +14,23 @@ module Hirb
|
|
14
14
|
# In addition to the config keys mentioned in Hirb, the options also take the following keys:
|
15
15
|
# Options:
|
16
16
|
# * config_file: Name of config file to read.
|
17
|
+
# * output_method: Specify an object's class and instance method (separated by a period) to be realiased with
|
18
|
+
# hirb's view system. The instance method should take a string to be output. Default is IRB::Irb.output_value
|
19
|
+
# if using irb.
|
17
20
|
# Examples:
|
18
21
|
# Hirb::View.enable
|
19
|
-
# Hirb::View.enable :formatter=>false
|
22
|
+
# Hirb::View.enable :formatter=>false, :output_method=>"Mini.output"
|
20
23
|
# Hirb::View.enable {|c| c.output = {'String'=>{:class=>'Hirb::Helpers::Table'}} }
|
21
24
|
def enable(options={}, &block)
|
22
25
|
return puts("Already enabled.") if @enabled
|
23
26
|
@enabled = true
|
24
27
|
Hirb.config_file = options.delete(:config_file) if options[:config_file]
|
28
|
+
output_method = "IRB::Irb.output_value" if Object.const_defined?(:IRB)
|
29
|
+
output_method = options.delete(:output_method) if options[:output_method]
|
25
30
|
load_config(Util.recursive_hash_merge(options, HashStruct.block_to_hash(block)))
|
26
31
|
resize(config[:width], config[:height])
|
27
|
-
if
|
28
|
-
|
29
|
-
alias :non_hirb_view_output :output_value
|
30
|
-
def output_value #:nodoc:
|
31
|
-
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
32
|
-
non_hirb_view_output
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
32
|
+
alias_output_method(output_method) if output_method
|
33
|
+
true
|
36
34
|
end
|
37
35
|
|
38
36
|
# Indicates if Hirb::View is enabled.
|
@@ -113,6 +111,26 @@ module Hirb
|
|
113
111
|
end
|
114
112
|
|
115
113
|
#:stopdoc:
|
114
|
+
def alias_output_method(output_method)
|
115
|
+
klass, klass_method = output_method.split(".")
|
116
|
+
eval %[
|
117
|
+
::#{klass}.class_eval do
|
118
|
+
alias :non_hirb_view_output :#{klass_method}
|
119
|
+
if '#{klass}' == "IRB::Irb"
|
120
|
+
def #{klass_method} #:nodoc:
|
121
|
+
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
122
|
+
non_hirb_view_output
|
123
|
+
end
|
124
|
+
else
|
125
|
+
def #{klass_method}(output_string) #:nodoc:
|
126
|
+
Hirb::View.view_output(output_string) || Hirb::View.page_output(output_string.inspect, true) ||
|
127
|
+
non_hirb_view_output(output_string)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
]
|
132
|
+
end
|
133
|
+
|
116
134
|
def render_output(output, options={})
|
117
135
|
if (formatted_output = formatter.format_output(output, options))
|
118
136
|
render_method.call(formatted_output)
|
data/test/formatter_test.rb
CHANGED
@@ -9,9 +9,11 @@ class FormatterTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
before(:all) { eval "module ::Dooda; end" }
|
11
11
|
|
12
|
-
test "klass_config merges ancestor options" do
|
13
|
-
set_formatter "String"=>{:args=>[1,2]
|
14
|
-
|
12
|
+
test "klass_config recursively merges ancestor options" do
|
13
|
+
set_formatter "String"=>{:args=>[1,2], :options=>{:fields=>[:to_s]}},
|
14
|
+
"Object"=>{:method=>:object_output, :ancestor=>true, :options=>{:vertical=>true}},
|
15
|
+
"Kernel"=>{:method=>:default_output}
|
16
|
+
expected_result = {:method=>:object_output, :args=>[1, 2], :ancestor=>true, :options=>{:fields=>[:to_s], :vertical=>true}}
|
15
17
|
@formatter.klass_config(::String).should == expected_result
|
16
18
|
end
|
17
19
|
|
data/test/view_test.rb
CHANGED
@@ -47,6 +47,13 @@ module Hirb
|
|
47
47
|
Hirb.enable :config_file=> 'test_file'
|
48
48
|
Hirb.config_file.should == 'test_file'
|
49
49
|
end
|
50
|
+
|
51
|
+
test "with output_method option realiases output_method" do
|
52
|
+
eval %[module ::Mini; extend self; def output(str); puts(str.inspect); end; end]
|
53
|
+
Hirb.enable :output_method=>"Mini.output", :output=>{"Symbol"=>{:output_method=>lambda {|e| e.to_s }}}
|
54
|
+
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
55
|
+
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
56
|
+
end
|
50
57
|
end
|
51
58
|
|
52
59
|
context "resize" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Horner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-01 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements: []
|
86
86
|
|
87
87
|
rubyforge_project: tagaholic
|
88
|
-
rubygems_version: 1.3.
|
88
|
+
rubygems_version: 1.3.5
|
89
89
|
signing_key:
|
90
90
|
specification_version: 3
|
91
91
|
summary: A mini view framework for console/irb that's easy to use, even while under its influence.
|