hirb 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +2 -2
- data/.travis.yml +1 -1
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +2 -2
- data/lib/hirb/helpers/table.rb +33 -9
- data/lib/hirb/version.rb +1 -1
- data/test/deps.rip +2 -2
- data/test/table_test.rb +13 -0
- data/test/test_helper.rb +0 -1
- metadata +10 -10
data/.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
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
13
|
s.required_rubygems_version = ">= 1.3.5"
|
14
14
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
15
|
-
s.add_development_dependency 'mocha', '
|
16
|
-
s.add_development_dependency 'mocha-on-bacon', '
|
15
|
+
s.add_development_dependency 'mocha', '~> 0.12.1'
|
16
|
+
s.add_development_dependency 'mocha-on-bacon', '~> 0.2.1'
|
17
17
|
s.add_development_dependency 'bacon-bits'
|
18
18
|
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} {.,test,spec}/deps.rip]) + %w{Rakefile .gemspec .travis.yml}
|
19
19
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -116,7 +116,7 @@ tables/views for any output object:
|
|
116
116
|
1 row in set
|
117
117
|
|
118
118
|
# Creates github-markdown
|
119
|
-
>> table [[:a, :b :c]], :markdown => true
|
119
|
+
>> table [[:a, :b, :c]], :markdown => true
|
120
120
|
| 0 | 1 | 2 |
|
121
121
|
|---|---|---|
|
122
122
|
| a | b | c |
|
@@ -187,7 +187,7 @@ Table code from http://gist.github.com/72234 and {my console app's needs}[http:/
|
|
187
187
|
* Chrononaut for vertical table helper.
|
188
188
|
* janlelis for unicode table helper.
|
189
189
|
* technogeeky and FND for markdown table helper.
|
190
|
-
* hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall and joshua for patches.
|
190
|
+
* hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall, maxmeyer, jimjh and joshua for patches.
|
191
191
|
|
192
192
|
== Bugs/Issues
|
193
193
|
Please report them {on github}[http://github.com/cldwalker/hirb/issues].
|
data/lib/hirb/helpers/table.rb
CHANGED
@@ -58,7 +58,7 @@ module Hirb
|
|
58
58
|
# For a thorough example, see {Boson::Pipe}[http://github.com/cldwalker/boson/blob/master/lib/boson/pipe.rb].
|
59
59
|
#--
|
60
60
|
# derived from http://gist.github.com/72234
|
61
|
-
|
61
|
+
class Helpers::Table
|
62
62
|
BORDER_LENGTH = 3 # " | " and "-+-" are the borders
|
63
63
|
MIN_FIELD_LENGTH = 3
|
64
64
|
class TooManyFieldsForWidthError < StandardError; end
|
@@ -95,13 +95,17 @@ module Hirb
|
|
95
95
|
# [*:filter_any*] When set to true, any cell defaults to being filtered by its class in :filter_classes.
|
96
96
|
# Default Hirb::Helpers::Table.filter_any().
|
97
97
|
# [*:filter_classes*] Hash which maps classes to filters. Default is Hirb::Helpers::Table.filter_classes().
|
98
|
-
# [*:vertical*] When set to true, renders a vertical table using Hirb::Helpers::VerticalTable. Default is false.
|
99
|
-
# [*:unicode*] When set to true, renders a unicode table using Hirb::Helpers::UnicodeTable. Default is false.
|
100
|
-
# [*:tab*] When set to true, renders a tab-delimited table using Hirb::Helpers::TabTable. Default is false.
|
101
98
|
# [*:all_fields*] When set to true, renders fields in all rows. Valid only in rows that are hashes. Default is false.
|
102
99
|
# [*:description*] When set to true, renders row count description at bottom. Default is true.
|
103
100
|
# [*:escape_special_chars*] When set to true, escapes special characters \n,\t,\r so they don't disrupt tables. Default is false for
|
104
101
|
# vertical tables and true for anything else.
|
102
|
+
# [*:vertical*] When set to true, renders a vertical table using Hirb::Helpers::VerticalTable. Default is false.
|
103
|
+
# [*:unicode*] When set to true, renders a unicode table using Hirb::Helpers::UnicodeTable. Default is false.
|
104
|
+
# [*:tab*] When set to true, renders a tab-delimited table using Hirb::Helpers::TabTable. Default is false.
|
105
|
+
# [*:style*] Choose style of table: :simple, :vertical, :unicode, :tab or :markdown. :simple
|
106
|
+
# just uses the default render. Other values map to a capitalized namespace in format
|
107
|
+
# Hirb::Helpers::OptionValTable.
|
108
|
+
#
|
105
109
|
# Examples:
|
106
110
|
# Hirb::Helpers::Table.render [[1,2], [2,3]]
|
107
111
|
# Hirb::Helpers::Table.render [[1,2], [2,3]], :max_fields=>{0=>10}, :header_filter=>:capitalize
|
@@ -109,18 +113,37 @@ module Hirb
|
|
109
113
|
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}]
|
110
114
|
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], :headers=>{:weight=>"Weight(lbs)"}
|
111
115
|
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], :filters=>{:age=>[:to_f]}
|
116
|
+
# Hirb::Helpers::Table.render [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], :style=> :simple}
|
112
117
|
def render(rows, options={})
|
113
|
-
|
114
|
-
options[:unicode] ? Helpers::UnicodeTable.render(rows, options) :
|
115
|
-
options[:tab] ? Helpers::TabTable.render(rows, options) :
|
116
|
-
options[:markdown] ? Helpers::MarkdownTable.render(rows, options) :
|
117
|
-
new(rows, options).render
|
118
|
+
choose_style(rows, options)
|
118
119
|
rescue TooManyFieldsForWidthError
|
119
120
|
$stderr.puts "", "** Hirb Warning: Too many fields for the current width. Configure your width " +
|
120
121
|
"and/or fields to avoid this error. Defaulting to a vertical table. **"
|
121
122
|
Helpers::VerticalTable.render(rows, options)
|
122
123
|
end
|
123
124
|
|
125
|
+
def choose_style(rows, options)
|
126
|
+
case options[:style]
|
127
|
+
when :vertical
|
128
|
+
Helpers::VerticalTable.render(rows, options)
|
129
|
+
when :unicode
|
130
|
+
Helpers::UnicodeTable.render(rows, options)
|
131
|
+
when :tab
|
132
|
+
Helpers::TabTable.render(rows, options)
|
133
|
+
when :markdown
|
134
|
+
Helpers::MarkdownTable.render(rows, options)
|
135
|
+
when :simple
|
136
|
+
new(rows, options).render
|
137
|
+
else
|
138
|
+
options[:vertical] ? Helpers::VerticalTable.render(rows, options) :
|
139
|
+
options[:unicode] ? Helpers::UnicodeTable.render(rows, options) :
|
140
|
+
options[:tab] ? Helpers::TabTable.render(rows, options) :
|
141
|
+
options[:markdown] ? Helpers::MarkdownTable.render(rows, options) :
|
142
|
+
new(rows, options).render
|
143
|
+
end
|
144
|
+
end
|
145
|
+
private :choose_style
|
146
|
+
|
124
147
|
# A hash which maps a cell value's class to a filter. This serves to set a default filter per field if all of its
|
125
148
|
# values are a class in this hash. By default, Array values are comma joined and Hashes are inspected.
|
126
149
|
# See the :filter_any option to apply this filter per value.
|
@@ -132,6 +155,7 @@ module Hirb
|
|
132
155
|
end
|
133
156
|
self.filter_classes = { Array=>:comma_join, Hash=>:inspect }
|
134
157
|
|
158
|
+
|
135
159
|
def chars
|
136
160
|
self.class.const_get(:CHARS)
|
137
161
|
end
|
data/lib/hirb/version.rb
CHANGED
data/test/deps.rip
CHANGED
data/test/table_test.rb
CHANGED
@@ -21,6 +21,19 @@ describe "Table" do
|
|
21
21
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}]).should == expected_table
|
22
22
|
end
|
23
23
|
|
24
|
+
it "also renders to the same table with :simple style given" do
|
25
|
+
expected_table = <<-TABLE.unindent
|
26
|
+
+---+---+
|
27
|
+
| a | b |
|
28
|
+
+---+---+
|
29
|
+
| 1 | 2 |
|
30
|
+
| 3 | 4 |
|
31
|
+
+---+---+
|
32
|
+
2 rows in set
|
33
|
+
TABLE
|
34
|
+
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :style => :simple).should == expected_table
|
35
|
+
end
|
36
|
+
|
24
37
|
it "with no headers renders" do
|
25
38
|
expected_table = <<-TABLE.unindent
|
26
39
|
+---+---+
|
data/test/test_helper.rb
CHANGED
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -32,33 +32,33 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.12.1
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.12.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: mocha-on-bacon
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
53
|
+
version: 0.2.1
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.2.1
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: bacon-bits
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|