hirb 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +22 -0
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +14 -4
- data/Rakefile +3 -3
- data/lib/hirb.rb +2 -0
- data/lib/hirb/helpers/object_table.rb +1 -1
- data/lib/hirb/menu.rb +3 -1
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +9 -4
- data/test/deps.rip +4 -0
- data/test/menu_test.rb +6 -0
- data/test/object_table_test.rb +6 -0
- data/test/test_helper.rb +2 -3
- data/test/view_test.rb +6 -0
- metadata +31 -9
- data/gemspec +0 -20
- data/test/bacon_extensions.rb +0 -26
data/.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
|
+
require File.dirname(__FILE__) + "/lib/hirb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hirb"
|
7
|
+
s.version = Hirb::VERSION
|
8
|
+
s.authors = ["Gabriel Horner"]
|
9
|
+
s.email = "gabriel.horner@gmail.com"
|
10
|
+
s.homepage = "http://tagaholic.me/hirb/"
|
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.6"
|
14
|
+
s.rubyforge_project = 'tagaholic'
|
15
|
+
s.add_development_dependency 'bacon', '>= 1.1.0'
|
16
|
+
s.add_development_dependency 'mocha'
|
17
|
+
s.add_development_dependency 'mocha-on-bacon'
|
18
|
+
s.add_development_dependency 'bacon-bits'
|
19
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
|
20
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
21
|
+
s.license = 'MIT'
|
22
|
+
end
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.3.3
|
2
|
+
* Added ignore_errors option to ignore view errors and continue with original view.
|
3
|
+
* Added support for array menu items.
|
4
|
+
* Added support to ObjectTable for objects with an undefined :send method.
|
5
|
+
|
1
6
|
== 0.3.2
|
2
7
|
* Added irb autocompletions for bond.
|
3
8
|
* Fixed tests for ruby 1.9.
|
data/README.rdoc
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
To read a linked version of this README, {click here}[http://tagaholic.me/hirb/doc/].
|
2
|
+
|
1
3
|
== Description
|
2
4
|
|
3
5
|
Hirb provides a mini view framework for console applications and uses it to improve irb's default inspect output.
|
@@ -8,8 +10,6 @@ i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and
|
|
8
10
|
only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer
|
9
11
|
{two dimensional menus}[http://tagaholic.me/2010/02/16/two-dimensional-console-menus-with-hirb.html].
|
10
12
|
|
11
|
-
Note: To read a linked version of this README, {click here}[http://tagaholic.me/hirb/doc/].
|
12
|
-
|
13
13
|
== Install
|
14
14
|
|
15
15
|
Install the gem with:
|
@@ -21,6 +21,16 @@ Install the gem with:
|
|
21
21
|
* To create and configure views, see Hirb::View or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/View.html].
|
22
22
|
* To create dynamic views, see Hirb::DynamicView or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/DynamicView.html].
|
23
23
|
|
24
|
+
== Printing Ascii Tables
|
25
|
+
|
26
|
+
To print ascii tables from an array of arrays, hashes or any objects:
|
27
|
+
|
28
|
+
puts Hirb::Helper::AutoTable.render(ARRAY_OF_OBJECTS)
|
29
|
+
|
30
|
+
Hirb will intelligently pick up on field names from an array of hashes and create properly-aligned
|
31
|
+
fields from an array of arrays. See
|
32
|
+
{here}[http://tagaholic.me/2009/10/15/boson-and-hirb-interactions.html#hirbs_handy_tables] for examples.
|
33
|
+
|
24
34
|
== Rails Example
|
25
35
|
|
26
36
|
Let's load and enable the view framework:
|
@@ -156,7 +166,7 @@ Table code from http://gist.github.com/72234 and {my console app's needs}[http:/
|
|
156
166
|
|
157
167
|
== Credits
|
158
168
|
* Chrononaut for vertical table helper.
|
159
|
-
* crafterm, spastorino, xaviershay and joshua for
|
169
|
+
* crafterm, spastorino, xaviershay, bogdan and joshua for patches.
|
160
170
|
|
161
171
|
== Bugs/Issues
|
162
172
|
Please report them {on github}[http://github.com/cldwalker/hirb/issues].
|
@@ -169,4 +179,4 @@ Please report them {on github}[http://github.com/cldwalker/hirb/issues].
|
|
169
179
|
== Todo
|
170
180
|
* Consider generating views based on methods an object responds to.
|
171
181
|
* Provide helper methods to all views.
|
172
|
-
* Consider adding a template helper.
|
182
|
+
* Consider adding a template helper.
|
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@ require 'rake'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
def gemspec
|
5
|
-
@gemspec ||= eval(File.read('gemspec'), binding, 'gemspec')
|
5
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
6
6
|
end
|
7
7
|
|
8
8
|
desc "Build the gem"
|
9
9
|
task :gem=>:gemspec do
|
10
|
-
sh "gem build gemspec"
|
10
|
+
sh "gem build .gemspec"
|
11
11
|
FileUtils.mkdir_p 'pkg'
|
12
12
|
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
13
|
end
|
@@ -32,4 +32,4 @@ task :test do |t|
|
|
32
32
|
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
33
33
|
end
|
34
34
|
|
35
|
-
task :default => :test
|
35
|
+
task :default => :test
|
data/lib/hirb.rb
CHANGED
@@ -26,6 +26,8 @@ require 'hirb/version'
|
|
26
26
|
# [*:pager*] Boolean which determines if the pager is enabled. Defaults to true.
|
27
27
|
# [*:pager_command*] Command to be used for paging. Command can have options after it i.e. 'less -r'.
|
28
28
|
# Defaults to common pagers i.e. less and more if detected.
|
29
|
+
# [*:ignore_errors*] Boolean which ignores internal view errors and continues with original view
|
30
|
+
# (i.e. #inspect for irb). Defaults to false.
|
29
31
|
module Hirb
|
30
32
|
class <<self
|
31
33
|
attr_accessor :config_files, :config
|
@@ -7,7 +7,7 @@ class Hirb::Helpers::ObjectTable < Hirb::Helpers::Table
|
|
7
7
|
options[:fields] ||= [:to_s]
|
8
8
|
options[:headers] ||= {:to_s=>'value'} if options[:fields] == [:to_s]
|
9
9
|
item_hashes = options[:fields].empty? ? [] : Array(rows).inject([]) {|t,item|
|
10
|
-
t << options[:fields].inject({}) {|h,f| h[f] = item.
|
10
|
+
t << options[:fields].inject({}) {|h,f| h[f] = item.__send__(f); h}
|
11
11
|
}
|
12
12
|
super(item_hashes, options)
|
13
13
|
end
|
data/lib/hirb/menu.rb
CHANGED
@@ -126,7 +126,9 @@ module Hirb
|
|
126
126
|
def map_tokens(tokens)
|
127
127
|
if return_cell_values?
|
128
128
|
@output[0].is_a?(Hash) ? tokens.map {|arr,f| arr.map {|e| e[f]} }.flatten :
|
129
|
-
tokens.map {|arr,f|
|
129
|
+
tokens.map {|arr,f|
|
130
|
+
arr.map {|e| e.is_a?(Array) && f.is_a?(Integer) ? e[f] : e.send(f) }
|
131
|
+
}.flatten
|
130
132
|
else
|
131
133
|
tokens.map {|e| e[0] }.flatten
|
132
134
|
end
|
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/view.rb
CHANGED
@@ -125,9 +125,14 @@ module Hirb
|
|
125
125
|
def view_output(output, options={})
|
126
126
|
enabled? && config[:formatter] && render_output(output, options)
|
127
127
|
rescue Exception=>e
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
if config[:ignore_errors]
|
129
|
+
$stderr.puts "Hirb Error: #{e.message}"
|
130
|
+
false
|
131
|
+
else
|
132
|
+
index = (obj = e.backtrace.find {|f| f =~ /^\(eval\)/}) ? e.backtrace.index(obj) : e.backtrace.length
|
133
|
+
$stderr.puts "Hirb Error: #{e.message}", e.backtrace.slice(0,index).map {|e| " " + e }
|
134
|
+
true
|
135
|
+
end
|
131
136
|
end
|
132
137
|
|
133
138
|
# Captures STDOUT and renders it using render_method(). The main use case is to conditionally page captured stdout.
|
@@ -276,4 +281,4 @@ module Hirb
|
|
276
281
|
#:startdoc:
|
277
282
|
end
|
278
283
|
end
|
279
|
-
end
|
284
|
+
end
|
data/test/deps.rip
ADDED
data/test/menu_test.rb
CHANGED
@@ -187,6 +187,12 @@ describe "Menu" do
|
|
187
187
|
capture_stderr { two_d_menu(:action=>true) }.should =~ /No command given/
|
188
188
|
end
|
189
189
|
|
190
|
+
it "with array menu items" do
|
191
|
+
menu_input "p 1"
|
192
|
+
two_d_menu :action=>true, :output=>[['some', 'choice'], ['and', 'another']],
|
193
|
+
:invokes=>[[['some']]]
|
194
|
+
end
|
195
|
+
|
190
196
|
it "with multi_action option invokes" do
|
191
197
|
menu_input "p 1 2:bro"
|
192
198
|
two_d_menu(:action=>true, :multi_action=>true, :invokes=>[[1], [4]])
|
data/test/object_table_test.rb
CHANGED
@@ -70,4 +70,10 @@ describe "object table" do
|
|
70
70
|
TABLE
|
71
71
|
table(@pets, :fields => []).should == expected_table
|
72
72
|
end
|
73
|
+
|
74
|
+
it "doesn't raise error for objects that don't have :send defined" do
|
75
|
+
object = Object.new
|
76
|
+
class<<object; self; end.send :undef_method, :send
|
77
|
+
should.not.raise(NoMethodError) { table([object], :fields=>[:to_s]) }
|
78
|
+
end
|
73
79
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'bacon'
|
2
|
-
require
|
2
|
+
require 'bacon/bits'
|
3
3
|
require 'mocha'
|
4
4
|
require 'mocha-on-bacon'
|
5
5
|
require 'hirb'
|
@@ -41,7 +41,6 @@ end
|
|
41
41
|
|
42
42
|
class Bacon::Context
|
43
43
|
include TestHelpers
|
44
|
-
include BaconExtensions
|
45
44
|
end
|
46
45
|
|
47
46
|
class String
|
@@ -59,4 +58,4 @@ module ::IRB
|
|
59
58
|
end
|
60
59
|
def output_value; end
|
61
60
|
end
|
62
|
-
end
|
61
|
+
end
|
data/test/view_test.rb
CHANGED
@@ -98,6 +98,12 @@ describe "View" do
|
|
98
98
|
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
99
99
|
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
100
100
|
end
|
101
|
+
|
102
|
+
it "with ignore_errors enable option" do
|
103
|
+
Hirb.enable :ignore_errors => true
|
104
|
+
View.stubs(:render_output).raises(Exception, "Ex mesg")
|
105
|
+
capture_stderr { View.view_output("").should == false }.should =~ /Error: Ex mesg/
|
106
|
+
end
|
101
107
|
end
|
102
108
|
|
103
109
|
describe "resize" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Gabriel Horner
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-14 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,9 +26,12 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
28
30
|
segments:
|
31
|
+
- 1
|
32
|
+
- 1
|
29
33
|
- 0
|
30
|
-
version:
|
34
|
+
version: 1.1.0
|
31
35
|
type: :development
|
32
36
|
version_requirements: *id001
|
33
37
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +42,7 @@ dependencies:
|
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
version: "0"
|
@@ -51,12 +56,27 @@ dependencies:
|
|
51
56
|
requirements:
|
52
57
|
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
54
60
|
segments:
|
55
61
|
- 0
|
56
62
|
version: "0"
|
57
63
|
type: :development
|
58
64
|
version_requirements: *id003
|
59
|
-
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: bacon-bits
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
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.
|
60
80
|
email: gabriel.horner@gmail.com
|
61
81
|
executables: []
|
62
82
|
|
@@ -94,7 +114,6 @@ files:
|
|
94
114
|
- lib/hirb/views.rb
|
95
115
|
- lib/hirb.rb
|
96
116
|
- test/auto_table_test.rb
|
97
|
-
- test/bacon_extensions.rb
|
98
117
|
- test/console_test.rb
|
99
118
|
- test/dynamic_view_test.rb
|
100
119
|
- test/formatter_test.rb
|
@@ -113,12 +132,13 @@ files:
|
|
113
132
|
- LICENSE.txt
|
114
133
|
- CHANGELOG.rdoc
|
115
134
|
- README.rdoc
|
135
|
+
- test/deps.rip
|
116
136
|
- Rakefile
|
117
|
-
- gemspec
|
137
|
+
- .gemspec
|
118
138
|
has_rdoc: true
|
119
139
|
homepage: http://tagaholic.me/hirb/
|
120
|
-
licenses:
|
121
|
-
|
140
|
+
licenses:
|
141
|
+
- MIT
|
122
142
|
post_install_message:
|
123
143
|
rdoc_options: []
|
124
144
|
|
@@ -129,6 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
149
|
requirements:
|
130
150
|
- - ">="
|
131
151
|
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
132
153
|
segments:
|
133
154
|
- 0
|
134
155
|
version: "0"
|
@@ -137,6 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
158
|
requirements:
|
138
159
|
- - ">="
|
139
160
|
- !ruby/object:Gem::Version
|
161
|
+
hash: 23
|
140
162
|
segments:
|
141
163
|
- 1
|
142
164
|
- 3
|
data/gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
|
-
require File.dirname(__FILE__) + "/lib/hirb/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "hirb"
|
7
|
-
s.version = Hirb::VERSION
|
8
|
-
s.authors = ["Gabriel Horner"]
|
9
|
-
s.email = "gabriel.horner@gmail.com"
|
10
|
-
s.homepage = "http://tagaholic.me/hirb/"
|
11
|
-
s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
|
12
|
-
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."
|
13
|
-
s.required_rubygems_version = ">= 1.3.6"
|
14
|
-
s.rubyforge_project = 'tagaholic'
|
15
|
-
s.add_development_dependency 'bacon'
|
16
|
-
s.add_development_dependency 'mocha'
|
17
|
-
s.add_development_dependency 'mocha-on-bacon'
|
18
|
-
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile gemspec}
|
19
|
-
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
20
|
-
end
|
data/test/bacon_extensions.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module BaconExtensions
|
2
|
-
def self.included(mod)
|
3
|
-
mod.module_eval do
|
4
|
-
# nested context methods automatically inherit methods from parent contexts
|
5
|
-
def describe(*args, &block)
|
6
|
-
context = Bacon::Context.new(args.join(' '), &block)
|
7
|
-
(parent_context = self).methods(false).each {|e|
|
8
|
-
class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
|
9
|
-
}
|
10
|
-
@before.each { |b| context.before(&b) }
|
11
|
-
@after.each { |b| context.after(&b) }
|
12
|
-
context.run
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def xit(*args); end
|
18
|
-
def xdescribe(*args); end
|
19
|
-
def before_all; yield; end
|
20
|
-
def after_all; yield; end
|
21
|
-
def assert(description, &block)
|
22
|
-
it(description) do
|
23
|
-
block.call.should == true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|