hirb 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/hirb.rb +2 -1
- data/lib/hirb/helpers/parent_child_tree.rb +4 -3
- data/lib/hirb/helpers/table.rb +4 -4
- data/lib/hirb/view.rb +15 -9
- data/test/hirb_test.rb +8 -1
- data/test/table_test.rb +27 -0
- data/test/tree_test.rb +12 -0
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.2.6
|
2
|
+
* Added :description option and added proc ability to :children_method option for helpers.
|
3
|
+
* Bug fix for no ENV['HOME'] on Windows.
|
4
|
+
* Bug fix on unaliasing output_method.
|
5
|
+
* Bug fix on multiple renders of vertical table.
|
6
|
+
|
1
7
|
== 0.2.5
|
2
8
|
* Added ability to use Hirb.enable with non-irb ruby shells.
|
3
9
|
* Helper configs now recursively merge when inheriting from others via :ancestor option.
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ begin
|
|
21
21
|
s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
|
22
22
|
s.description = "Hirb currently provides a mini view framework for console applications, designed to improve irb's default output. Hirb improves console output by providing a smart pager and auto-formatting output. The smart pager detects when an output exceeds a screenful and thus only pages output as needed. Auto-formatting adds a view to an output's class. This is helpful in separating views from content (MVC anyone?). The framework encourages reusing views by letting you package them in classes and associate them with any number of output classes."
|
23
23
|
s.email = "gabriel.horner@gmail.com"
|
24
|
-
s.homepage = "http://
|
24
|
+
s.homepage = "http://tagaholic.me/hirb/"
|
25
25
|
s.authors = ["Gabriel Horner"]
|
26
26
|
s.rubyforge_project = 'tagaholic'
|
27
27
|
s.has_rdoc = true
|
data/VERSION.yml
CHANGED
data/lib/hirb.rb
CHANGED
@@ -41,7 +41,8 @@ module Hirb
|
|
41
41
|
end
|
42
42
|
# Default is config/hirb.yml or ~/hirb.yml in that order.
|
43
43
|
def config_file
|
44
|
-
@config_file ||= File.exists?('config/hirb.yml') ? 'config/hirb.yml' :
|
44
|
+
@config_file ||= File.exists?('config/hirb.yml') ? 'config/hirb.yml' :
|
45
|
+
File.expand_path(File.join(ENV["HOME"] || ".", ".hirb.yml"))
|
45
46
|
end
|
46
47
|
|
47
48
|
#:stopdoc:
|
@@ -5,7 +5,7 @@ class Hirb::Helpers::ParentChildTree < Hirb::Helpers::Tree
|
|
5
5
|
# ==== Options:
|
6
6
|
# [:value_method] Method to call to display as a node's value. If not given, uses :name if node
|
7
7
|
# responds to :name or defaults to :object_id.
|
8
|
-
# [:children_method] Method to call to obtain a node's children. Default is :children.
|
8
|
+
# [:children_method] Method or proc to call to obtain a node's children. Default is :children.
|
9
9
|
def render(root_node, options={})
|
10
10
|
@value_method = options[:value_method] || (root_node.respond_to?(:name) ? :name : :object_id)
|
11
11
|
@children_method = options[:children_method] || :children
|
@@ -16,7 +16,8 @@ class Hirb::Helpers::ParentChildTree < Hirb::Helpers::Tree
|
|
16
16
|
|
17
17
|
def build_node(node, level) #:nodoc:
|
18
18
|
@nodes << {:value=>node.send(@value_method), :level=>level}
|
19
|
-
|
19
|
+
children = @children_method.is_a?(Proc) ? @children_method.call(node) : node.send(@children_method)
|
20
|
+
children.each {|e| build_node(e, level + 1)}
|
20
21
|
end
|
21
22
|
end
|
22
|
-
end
|
23
|
+
end
|
data/lib/hirb/helpers/table.rb
CHANGED
@@ -46,6 +46,7 @@ module Hirb
|
|
46
46
|
# a given proc or an array containing a method and optional arguments to it.
|
47
47
|
# [:vertical] When set to true, renders a vertical table using Hirb::Helpers::VerticalTable. Default is false.
|
48
48
|
# [:all_fields] When set to true, renders fields in all rows. Valid only in rows that are hashes. Default is false.
|
49
|
+
# [:description] When set to true, renders row count description at bottom. Default is true.
|
49
50
|
# Examples:
|
50
51
|
# Hirb::Helpers::Table.render [[1,2], [2,3]]
|
51
52
|
# Hirb::Helpers::Table.render [[1,2], [2,3]], :field_lengths=>{0=>10}
|
@@ -53,7 +54,7 @@ module Hirb
|
|
53
54
|
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], :headers=>{:weight=>"Weight(lbs)"}
|
54
55
|
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], :filters=>{:age=>[:to_f]}
|
55
56
|
def render(rows, options={})
|
56
|
-
options
|
57
|
+
options[:vertical] ? Helpers::VerticalTable.render(rows, options) : new(rows, options).render
|
57
58
|
rescue TooManyFieldsForWidthError
|
58
59
|
$stderr.puts "", "** Error: Too many fields for the current width. Configure your width " +
|
59
60
|
"and/or fields to avoid this error. Defaulting to a vertical table. **"
|
@@ -63,8 +64,7 @@ module Hirb
|
|
63
64
|
|
64
65
|
#:stopdoc:
|
65
66
|
def initialize(rows, options={})
|
66
|
-
@options = options
|
67
|
-
@options[:filters] ||= {}
|
67
|
+
@options = {:description=>true, :filters=>{}}.merge(options)
|
68
68
|
@fields = set_fields(rows)
|
69
69
|
@rows = setup_rows(rows)
|
70
70
|
@headers = @fields.inject({}) {|h,e| h[e] = e.to_s; h}
|
@@ -113,7 +113,7 @@ module Hirb
|
|
113
113
|
body += render_rows
|
114
114
|
body += render_footer
|
115
115
|
end
|
116
|
-
body << render_table_description
|
116
|
+
body << render_table_description if @options[:description]
|
117
117
|
body.join("\n")
|
118
118
|
end
|
119
119
|
|
data/lib/hirb/view.rb
CHANGED
@@ -25,11 +25,11 @@ module Hirb
|
|
25
25
|
return puts("Already enabled.") if @enabled
|
26
26
|
@enabled = true
|
27
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]
|
28
|
+
@output_method = "IRB::Irb.output_value" if Object.const_defined?(:IRB)
|
29
|
+
@output_method = options.delete(:output_method) if options[:output_method]
|
30
30
|
load_config(Util.recursive_hash_merge(options, HashStruct.block_to_hash(block)))
|
31
31
|
resize(config[:width], config[:height])
|
32
|
-
alias_output_method(output_method) if output_method
|
32
|
+
alias_output_method(@output_method) if @output_method
|
33
33
|
true
|
34
34
|
end
|
35
35
|
|
@@ -41,11 +41,8 @@ module Hirb
|
|
41
41
|
# Disable's Hirb's output and revert's irb's output method if irb exists.
|
42
42
|
def disable
|
43
43
|
@enabled = false
|
44
|
-
if
|
45
|
-
|
46
|
-
alias :output_value :non_hirb_view_output
|
47
|
-
end
|
48
|
-
end
|
44
|
+
unalias_output_method(@output_method) if @output_method
|
45
|
+
false
|
49
46
|
end
|
50
47
|
|
51
48
|
# Toggles pager on or off. The pager only works while Hirb::View is enabled.
|
@@ -111,11 +108,20 @@ module Hirb
|
|
111
108
|
end
|
112
109
|
|
113
110
|
#:stopdoc:
|
111
|
+
def unalias_output_method(output_method)
|
112
|
+
klass, klass_method = output_method.split(".")
|
113
|
+
eval %[
|
114
|
+
::#{klass}.class_eval do
|
115
|
+
alias_method :#{klass_method}, :non_hirb_view_output
|
116
|
+
end
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
114
120
|
def alias_output_method(output_method)
|
115
121
|
klass, klass_method = output_method.split(".")
|
116
122
|
eval %[
|
117
123
|
::#{klass}.class_eval do
|
118
|
-
|
124
|
+
alias_method :non_hirb_view_output, :#{klass_method}
|
119
125
|
if '#{klass}' == "IRB::Irb"
|
120
126
|
def #{klass_method} #:nodoc:
|
121
127
|
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
data/test/hirb_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
|
3
3
|
class HirbTest < Test::Unit::TestCase
|
4
4
|
before(:each) {Hirb.instance_eval "@config = nil"}
|
5
|
-
|
5
|
+
|
6
6
|
test "config converts yaml when config file exists" do
|
7
7
|
yaml_data = {:blah=>'blah'}
|
8
8
|
File.stubs('exists?').returns(true)
|
@@ -20,4 +20,11 @@ class HirbTest < Test::Unit::TestCase
|
|
20
20
|
Hirb.expects(:read_config_file)
|
21
21
|
Hirb.config(true)
|
22
22
|
end
|
23
|
+
|
24
|
+
test "config_file sets correctly when no ENV['HOME']" do
|
25
|
+
Hirb.config_file = nil
|
26
|
+
home = ENV.delete('HOME')
|
27
|
+
Hirb.config_file.class.should == String
|
28
|
+
ENV["HOME"] = home
|
29
|
+
end
|
23
30
|
end
|
data/test/table_test.rb
CHANGED
@@ -266,6 +266,18 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
266
266
|
table([['a','b'], ['c', 'd']], :number=>true).should == expected_table
|
267
267
|
end
|
268
268
|
|
269
|
+
test "description option false renders" do
|
270
|
+
expected_table = <<-TABLE.unindent
|
271
|
+
+---+---+
|
272
|
+
| 0 | 1 |
|
273
|
+
+---+---+
|
274
|
+
| a | b |
|
275
|
+
| c | d |
|
276
|
+
+---+---+
|
277
|
+
TABLE
|
278
|
+
table([['a','b'], ['c', 'd']], :description=>false).should == expected_table
|
279
|
+
end
|
280
|
+
|
269
281
|
test "vertical option renders vertical table" do
|
270
282
|
expected_table = <<-TABLE.unindent
|
271
283
|
*** 1. row ***
|
@@ -279,6 +291,21 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
279
291
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :vertical=>true).should == expected_table
|
280
292
|
end
|
281
293
|
|
294
|
+
test "vertical option renders vertical table successively" do
|
295
|
+
expected_table = <<-TABLE.unindent
|
296
|
+
*** 1. row ***
|
297
|
+
a: 1
|
298
|
+
b: 2
|
299
|
+
*** 2. row ***
|
300
|
+
a: 3
|
301
|
+
b: 4
|
302
|
+
2 rows in set
|
303
|
+
TABLE
|
304
|
+
options = {:vertical=>true}
|
305
|
+
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], options).should == expected_table
|
306
|
+
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], options).should == expected_table
|
307
|
+
end
|
308
|
+
|
282
309
|
test "all_fields option renders all fields" do
|
283
310
|
expected_table = <<-TABLE.unindent
|
284
311
|
+---+---+---+
|
data/test/tree_test.rb
CHANGED
@@ -151,6 +151,18 @@ class Hirb::Helpers::TreeTest < Test::Unit::TestCase
|
|
151
151
|
root = mock_node(['0.0', ['1.1', ['2.1', '3.2'], '4.1']], :blah)
|
152
152
|
Hirb::Helpers::ParentChildTree.render(root, :type=>:directory, :value_method=>:blah).should == expected_tree
|
153
153
|
end
|
154
|
+
|
155
|
+
test "with children_method proc option renders" do
|
156
|
+
expected_tree = <<-TREE.unindent
|
157
|
+
1
|
158
|
+
|-- 2
|
159
|
+
|-- 3
|
160
|
+
|-- 4
|
161
|
+
`-- 5
|
162
|
+
TREE
|
163
|
+
Hirb::Helpers::ParentChildTree.render(1, :type=>:directory,
|
164
|
+
:children_method=>lambda {|e| e == 1 ? (2..5).to_a : []}, :value_method=>:to_s)
|
165
|
+
end
|
154
166
|
end
|
155
167
|
|
156
168
|
test "tree with parentless nodes renders ParentlessNodeError" 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.6
|
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-09-17 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -62,7 +62,7 @@ files:
|
|
62
62
|
- test/util_test.rb
|
63
63
|
- test/view_test.rb
|
64
64
|
has_rdoc: true
|
65
|
-
homepage: http://
|
65
|
+
homepage: http://tagaholic.me/hirb/
|
66
66
|
licenses: []
|
67
67
|
|
68
68
|
post_install_message:
|