hirb 0.3.4 → 0.3.6
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/.gemspec +2 -2
- data/CHANGELOG.rdoc +11 -0
- data/README.rdoc +5 -5
- data/lib/hirb/formatter.rb +4 -1
- data/lib/hirb/helpers/table.rb +1 -1
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +21 -35
- data/lib/ripl/hirb.rb +15 -0
- data/test/formatter_test.rb +14 -4
- data/test/table_test.rb +13 -0
- data/test/view_test.rb +0 -7
- metadata +9 -8
data/.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = "gabriel.horner@gmail.com"
|
10
10
|
s.homepage = "http://tagaholic.me/hirb/"
|
11
11
|
s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
|
12
|
-
s.description = "Hirb provides a mini view framework for console applications and uses it to improve irb's default inspect output. Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer two dimensional menus."
|
13
|
-
s.required_rubygems_version = ">= 1.3.
|
12
|
+
s.description = "Hirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output. Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer two dimensional menus."
|
13
|
+
s.required_rubygems_version = ">= 1.3.5"
|
14
14
|
s.rubyforge_project = 'tagaholic'
|
15
15
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
16
16
|
s.add_development_dependency 'mocha'
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 0.3.6
|
2
|
+
* Tweak ripl support
|
3
|
+
* Allow override of :hirb_number thanks to asanghi.
|
4
|
+
* Fix Hirb.add_view to work with class which inherits Hash
|
5
|
+
|
6
|
+
== 0.3.5
|
7
|
+
* Add ripl support
|
8
|
+
* Fix Formatter#determine_output_class for IO and Hash
|
9
|
+
* Remove :output_method option for Hirb.enable
|
10
|
+
* Allow rubygems 1.3.5
|
11
|
+
|
1
12
|
== 0.3.4
|
2
13
|
* Added auto format of array-like objects i.e. ActiveRecord::Relation and Set.
|
3
14
|
* Fixed bug when Hirb::Console#table is used without Hirb enabled.
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@ To read a linked version of this README, {click here}[http://tagaholic.me/hirb/d
|
|
2
2
|
|
3
3
|
== Description
|
4
4
|
|
5
|
-
Hirb provides a mini view framework for console applications and uses it to improve irb's default inspect output.
|
5
|
+
Hirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output.
|
6
6
|
Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable
|
7
7
|
views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options
|
8
8
|
for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems
|
@@ -14,7 +14,7 @@ only pages when the output exceeds the current screen size. The menu is used in
|
|
14
14
|
|
15
15
|
Install the gem with:
|
16
16
|
|
17
|
-
|
17
|
+
gem install hirb
|
18
18
|
|
19
19
|
== View Tutorials
|
20
20
|
|
@@ -25,7 +25,7 @@ Install the gem with:
|
|
25
25
|
|
26
26
|
To print ascii tables from an array of arrays, hashes or any objects:
|
27
27
|
|
28
|
-
puts Hirb::
|
28
|
+
puts Hirb::Helpers::AutoTable.render(ARRAY_OF_OBJECTS)
|
29
29
|
|
30
30
|
Hirb will intelligently pick up on field names from an array of hashes and create properly-aligned
|
31
31
|
fields from an array of arrays. See
|
@@ -159,14 +159,14 @@ views for certain classes, put them under lib/hirb/views. Please submit views fo
|
|
159
159
|
number of users.
|
160
160
|
|
161
161
|
== Limitations
|
162
|
-
If using Wirble, you should call Hirb after it since they both override irb's default output.
|
162
|
+
If using Wirble and irb, you should call Hirb after it since they both override irb's default output.
|
163
163
|
|
164
164
|
== Motivation
|
165
165
|
Table code from http://gist.github.com/72234 and {my console app's needs}[http://github.com/cldwalker/tag-tree].
|
166
166
|
|
167
167
|
== Credits
|
168
168
|
* Chrononaut for vertical table helper.
|
169
|
-
* crafterm, spastorino, xaviershay, bogdan and joshua for patches.
|
169
|
+
* crafterm, spastorino, xaviershay, bogdan, asanghi and joshua for patches.
|
170
170
|
|
171
171
|
== Bugs/Issues
|
172
172
|
Please report them {on github}[http://github.com/cldwalker/hirb/issues].
|
data/lib/hirb/formatter.rb
CHANGED
@@ -2,6 +2,8 @@ module Hirb
|
|
2
2
|
# A Formatter object formats an output object (using Formatter.format_output) into a string based on the views defined
|
3
3
|
# for its class and/or ancestry.
|
4
4
|
class Formatter
|
5
|
+
TO_A_EXCEPTIONS = [Hash, IO]
|
6
|
+
|
5
7
|
class<<self
|
6
8
|
# This config is used by Formatter.format_output to lazily load dynamic views defined with Hirb::DynamicView.
|
7
9
|
# This hash has the same format as Formatter.config.
|
@@ -75,7 +77,8 @@ module Hirb
|
|
75
77
|
end
|
76
78
|
|
77
79
|
def determine_output_class(output)
|
78
|
-
output.respond_to?(:to_a) ?
|
80
|
+
output.respond_to?(:to_a) && !TO_A_EXCEPTIONS.any? {|e| output.is_a?(e) } ?
|
81
|
+
Array(output)[0].class : output.class
|
79
82
|
end
|
80
83
|
|
81
84
|
def call_output_method(output_method, output)
|
data/lib/hirb/helpers/table.rb
CHANGED
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/view.rb
CHANGED
@@ -72,18 +72,15 @@ module Hirb
|
|
72
72
|
# or as options to this method. In addition to the config keys mentioned in Hirb, options also take the following keys:
|
73
73
|
# ==== Options:
|
74
74
|
# * config_file: Name of config file(s) that are merged into existing config
|
75
|
-
# * output_method: Specify an object's class and instance method (separated by a period) to be realiased with
|
76
|
-
# hirb's view system. The instance method should take a string to be output. Default is IRB::Irb.output_value
|
77
|
-
# if using irb.
|
78
75
|
# Examples:
|
79
76
|
# Hirb.enable
|
80
|
-
# Hirb.enable :formatter=>false
|
77
|
+
# Hirb.enable :formatter=>false
|
81
78
|
def enable(options={}, &block)
|
82
79
|
Array(options.delete(:config_file)).each {|e|
|
83
80
|
@new_config_file = true
|
84
81
|
Hirb.config_files << e
|
85
82
|
}
|
86
|
-
enable_output_method
|
83
|
+
enable_output_method unless @output_method
|
87
84
|
merge_or_load_config options
|
88
85
|
resize(config[:width], config[:height])
|
89
86
|
@enabled = true
|
@@ -97,7 +94,7 @@ module Hirb
|
|
97
94
|
# Disable's Hirb's output and revert's irb's output method if irb exists.
|
98
95
|
def disable
|
99
96
|
@enabled = false
|
100
|
-
|
97
|
+
disable_output_method if @output_method
|
101
98
|
false
|
102
99
|
end
|
103
100
|
|
@@ -177,41 +174,30 @@ module Hirb
|
|
177
174
|
end
|
178
175
|
|
179
176
|
#:stopdoc:
|
180
|
-
def enable_output_method
|
181
|
-
if
|
182
|
-
@output_method =
|
183
|
-
|
177
|
+
def enable_output_method
|
178
|
+
if defined? Ripl
|
179
|
+
@output_method = true
|
180
|
+
require 'ripl/hirb'
|
181
|
+
elsif defined? IRB
|
182
|
+
@output_method = true
|
183
|
+
::IRB::Irb.class_eval do
|
184
|
+
alias_method :non_hirb_view_output, :output_value
|
185
|
+
def output_value #:nodoc:
|
186
|
+
Hirb::View.view_or_page_output(@context.last_value) || non_hirb_view_output
|
187
|
+
end
|
188
|
+
end
|
184
189
|
end
|
185
190
|
end
|
186
191
|
|
187
|
-
def
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
alias_method :#{klass_method}, :non_hirb_view_output
|
192
|
-
end
|
193
|
-
]
|
192
|
+
def disable_output_method
|
193
|
+
if defined?(IRB) && !defined? Ripl
|
194
|
+
::IRB::Irb.send :alias_method, :output_value, :non_hirb_view_output
|
195
|
+
end
|
194
196
|
@output_method = nil
|
195
197
|
end
|
196
198
|
|
197
|
-
def
|
198
|
-
|
199
|
-
eval %[
|
200
|
-
::#{klass}.class_eval do
|
201
|
-
alias_method :non_hirb_view_output, :#{klass_method}
|
202
|
-
if '#{klass}' == "IRB::Irb"
|
203
|
-
def #{klass_method} #:nodoc:
|
204
|
-
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
205
|
-
non_hirb_view_output
|
206
|
-
end
|
207
|
-
else
|
208
|
-
def #{klass_method}(output_string) #:nodoc:
|
209
|
-
Hirb::View.view_output(output_string) || Hirb::View.page_output(output_string.inspect, true) ||
|
210
|
-
non_hirb_view_output(output_string)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
]
|
199
|
+
def view_or_page_output(str)
|
200
|
+
view_output(str) || page_output(str.inspect, true)
|
215
201
|
end
|
216
202
|
|
217
203
|
def render_output(output, options={})
|
data/lib/ripl/hirb.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'hirb'
|
2
|
+
|
3
|
+
module Ripl::Hirb
|
4
|
+
def before_loop
|
5
|
+
super
|
6
|
+
Hirb.enable(Ripl.config[:hirb] || {})
|
7
|
+
end
|
8
|
+
|
9
|
+
def format_result(result)
|
10
|
+
return super if !Hirb::View.enabled?
|
11
|
+
Hirb::View.view_or_page_output(result) || super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Ripl::Shell.send :include, Ripl::Hirb
|
data/test/formatter_test.rb
CHANGED
@@ -53,24 +53,34 @@ describe "Formatter" do
|
|
53
53
|
describe "formatter methods:" do
|
54
54
|
before_all { eval "module ::Dooda; end" }
|
55
55
|
|
56
|
-
it "add_view sets formatter config" do
|
56
|
+
it "#add_view sets formatter config" do
|
57
57
|
@formatter = set_formatter
|
58
58
|
@formatter.add_view ::Dooda, :class=>"DoodaView"
|
59
59
|
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView"}
|
60
60
|
end
|
61
61
|
|
62
|
-
it "add_view overwrites existing formatter config" do
|
62
|
+
it "#add_view overwrites existing formatter config" do
|
63
63
|
@formatter = set_formatter "Dooda"=>{:class=>"DoodaView"}
|
64
64
|
@formatter.add_view ::Dooda, :class=>"DoodaView2"
|
65
65
|
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView2"}
|
66
66
|
end
|
67
67
|
|
68
|
-
it "parse_console_options passes all options except for formatter options into :options" do
|
68
|
+
it "#parse_console_options passes all options except for formatter options into :options" do
|
69
69
|
@formatter = set_formatter
|
70
70
|
options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :blah=>'blah'}
|
71
71
|
expected_options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :options=>{:blah=>'blah'}}
|
72
72
|
@formatter.parse_console_options(options).should == expected_options
|
73
73
|
end
|
74
|
+
|
75
|
+
it "#determine_output_class bypasses exceptions for to_a" do
|
76
|
+
@formatter.determine_output_class(STDOUT).should == IO
|
77
|
+
@formatter.determine_output_class({:a=>1}).should == Hash
|
78
|
+
end
|
79
|
+
|
80
|
+
it "#determine_output_class bypasses subclasses of exceptions for to_a" do
|
81
|
+
class Hash2 < Hash; end
|
82
|
+
@formatter.determine_output_class(Hash2[1=>2]).should == Hash2
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
86
|
describe "format_output" do
|
@@ -124,7 +134,7 @@ describe "Formatter" do
|
|
124
134
|
require 'set'
|
125
135
|
view_output Set.new(['dude'])
|
126
136
|
end
|
127
|
-
|
137
|
+
|
128
138
|
it "formats with options option" do
|
129
139
|
eval "module ::Blahify; def self.render(*args); end; end"
|
130
140
|
enable_with_output "String"=>{:class=>"Blahify", :options=>{:fields=>%w{a b}}}
|
data/test/table_test.rb
CHANGED
@@ -361,6 +361,19 @@ describe "Table" do
|
|
361
361
|
table([['a','b'], ['c', 'd']], :number=>true).should == expected_table
|
362
362
|
end
|
363
363
|
|
364
|
+
it "number option renders with header that can be overridden" do
|
365
|
+
expected_table = <<-TABLE.unindent
|
366
|
+
+----+---+---+
|
367
|
+
| SR | 0 | 1 |
|
368
|
+
+----+---+---+
|
369
|
+
| 1 | a | b |
|
370
|
+
| 2 | c | d |
|
371
|
+
+----+---+---+
|
372
|
+
2 rows in set
|
373
|
+
TABLE
|
374
|
+
table([['a','b'], ['c', 'd']], :number=>true, :headers => {:hirb_number => "SR"}).should == expected_table
|
375
|
+
end
|
376
|
+
|
364
377
|
it "description option false renders" do
|
365
378
|
expected_table = <<-TABLE.unindent
|
366
379
|
+---+---+
|
data/test/view_test.rb
CHANGED
@@ -92,13 +92,6 @@ describe "View" do
|
|
92
92
|
Hirb.config_files.include?('test_file').should == true
|
93
93
|
end
|
94
94
|
|
95
|
-
it "with output_method option realiases output_method" do
|
96
|
-
eval %[module ::Mini; extend self; def output(str); puts(str.inspect); end; end]
|
97
|
-
Hirb.enable :output_method=>"Mini.output", :output=>{"Symbol"=>{:output_method=>lambda {|e| e.to_s }}}
|
98
|
-
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
99
|
-
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
100
|
-
end
|
101
|
-
|
102
95
|
it "with ignore_errors enable option" do
|
103
96
|
Hirb.enable :ignore_errors => true
|
104
97
|
View.stubs(:render_output).raises(Exception, "Ex mesg")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 6
|
10
|
+
version: 0.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabriel Horner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: "0"
|
77
77
|
type: :development
|
78
78
|
version_requirements: *id004
|
79
|
-
description: Hirb provides a mini view framework for console applications and uses it to improve irb's default inspect output. Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer two dimensional menus.
|
79
|
+
description: Hirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output. Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer two dimensional menus.
|
80
80
|
email: gabriel.horner@gmail.com
|
81
81
|
executables: []
|
82
82
|
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/hirb/views/rails.rb
|
114
114
|
- lib/hirb/views.rb
|
115
115
|
- lib/hirb.rb
|
116
|
+
- lib/ripl/hirb.rb
|
116
117
|
- test/auto_table_test.rb
|
117
118
|
- test/console_test.rb
|
118
119
|
- test/dynamic_view_test.rb
|
@@ -158,12 +159,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
requirements:
|
159
160
|
- - ">="
|
160
161
|
- !ruby/object:Gem::Version
|
161
|
-
hash:
|
162
|
+
hash: 17
|
162
163
|
segments:
|
163
164
|
- 1
|
164
165
|
- 3
|
165
|
-
-
|
166
|
-
version: 1.3.
|
166
|
+
- 5
|
167
|
+
version: 1.3.5
|
167
168
|
requirements: []
|
168
169
|
|
169
170
|
rubyforge_project: tagaholic
|