hirber 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemspec +21 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +165 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +205 -0
- data/Rakefile +35 -0
- data/lib/bond/completions/hirb.rb +15 -0
- data/lib/hirb.rb +84 -0
- data/lib/hirb/console.rb +43 -0
- data/lib/hirb/dynamic_view.rb +113 -0
- data/lib/hirb/formatter.rb +126 -0
- data/lib/hirb/helpers.rb +18 -0
- data/lib/hirb/helpers/auto_table.rb +24 -0
- data/lib/hirb/helpers/markdown_table.rb +14 -0
- data/lib/hirb/helpers/object_table.rb +14 -0
- data/lib/hirb/helpers/parent_child_tree.rb +24 -0
- data/lib/hirb/helpers/tab_table.rb +24 -0
- data/lib/hirb/helpers/table.rb +376 -0
- data/lib/hirb/helpers/table/filters.rb +10 -0
- data/lib/hirb/helpers/table/resizer.rb +82 -0
- data/lib/hirb/helpers/tree.rb +181 -0
- data/lib/hirb/helpers/unicode_table.rb +15 -0
- data/lib/hirb/helpers/vertical_table.rb +37 -0
- data/lib/hirb/import_object.rb +10 -0
- data/lib/hirb/menu.rb +226 -0
- data/lib/hirb/pager.rb +106 -0
- data/lib/hirb/string.rb +44 -0
- data/lib/hirb/util.rb +96 -0
- data/lib/hirb/version.rb +3 -0
- data/lib/hirb/view.rb +272 -0
- data/lib/hirb/views.rb +8 -0
- data/lib/hirb/views/couch_db.rb +11 -0
- data/lib/hirb/views/misc_db.rb +15 -0
- data/lib/hirb/views/mongo_db.rb +17 -0
- data/lib/hirb/views/orm.rb +11 -0
- data/lib/hirb/views/rails.rb +19 -0
- data/lib/ripl/hirb.rb +15 -0
- data/test/auto_table_test.rb +33 -0
- data/test/console_test.rb +27 -0
- data/test/dynamic_view_test.rb +94 -0
- data/test/formatter_test.rb +176 -0
- data/test/hirb_test.rb +39 -0
- data/test/import_test.rb +9 -0
- data/test/menu_test.rb +272 -0
- data/test/object_table_test.rb +79 -0
- data/test/pager_test.rb +162 -0
- data/test/resizer_test.rb +62 -0
- data/test/table_test.rb +667 -0
- data/test/test_helper.rb +60 -0
- data/test/tree_test.rb +184 -0
- data/test/util_test.rb +59 -0
- data/test/view_test.rb +178 -0
- data/test/views_test.rb +22 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6b4c2b50b223ed2bc25c02e75f8da31092cd5aeeadf45170911cccdc360f018
|
4
|
+
data.tar.gz: d0a324052cf7733e17ccdc73c7257f5a5f1ae47ba1e8846e87815e18f67211df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2e6e353265c0f0b870a18388b6ea1fb0a5f91f0cd8ae7e48a8410a4cf9daaba718955a426e8edf5b1f324466366b0046dc53f5930add2061aec0354c3201fbb
|
7
|
+
data.tar.gz: 06500e38016b65255cacf7a269d38ca62dc781f85e90f4c5b5ab9cad179a9c48a9eb0ec2a8fd08ae6e81b54e6a84bcfd69dbba2656e42d85cdb83b136512525c
|
data/.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
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 = "hirber"
|
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 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
|
+
s.add_development_dependency 'bacon', '>= 1.1.0'
|
15
|
+
s.add_development_dependency 'mocha', '~> 0.12.1'
|
16
|
+
s.add_development_dependency 'mocha-on-bacon', '~> 0.2.1'
|
17
|
+
s.add_development_dependency 'bacon-bits'
|
18
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc,md} ext/**/*.{rb,c}]) + %w{Rakefile .gemspec .travis.yml}
|
19
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
20
|
+
s.license = 'MIT'
|
21
|
+
end
|
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
== 0.7.3
|
2
|
+
* Remove warnings
|
3
|
+
|
4
|
+
== 0.7.2
|
5
|
+
* Allow full paths on $PAGER
|
6
|
+
* Fix AR tables with no id column
|
7
|
+
|
8
|
+
== 0.7.1
|
9
|
+
* Add :style option
|
10
|
+
* Fix mocha dep issue
|
11
|
+
|
12
|
+
== 0.7.0
|
13
|
+
* Add github markdown table
|
14
|
+
|
15
|
+
== 0.6.2
|
16
|
+
* Add * support to 1d/2d menus
|
17
|
+
|
18
|
+
== 0.6.1
|
19
|
+
* Fix for mongoid view
|
20
|
+
* Fix tests on rubinius + jruby
|
21
|
+
|
22
|
+
== 0.6.0
|
23
|
+
* Add tab table
|
24
|
+
* Tests pass in 1.9.3
|
25
|
+
|
26
|
+
== 0.5.0
|
27
|
+
* Add :grep_fields option to Table
|
28
|
+
|
29
|
+
== 0.4.5
|
30
|
+
* Fix the fix
|
31
|
+
|
32
|
+
== 0.4.4
|
33
|
+
* Fix bundler messing with ripl plugin
|
34
|
+
|
35
|
+
== 0.4.3
|
36
|
+
* Remove Formatter::TO_A_EXCEPTIONS and replace with Formatter.to_a_classes
|
37
|
+
|
38
|
+
== 0.4.2
|
39
|
+
* Fix bug with Tempfile and to_a_exceptions
|
40
|
+
|
41
|
+
== 0.4.1
|
42
|
+
* Fix bug with rendering empty hash
|
43
|
+
* Add missing yaml require
|
44
|
+
|
45
|
+
== 0.4.0
|
46
|
+
* Add unicode table helper thanks to janlelis
|
47
|
+
* Make pager compatible with full width characters
|
48
|
+
|
49
|
+
== 0.3.6
|
50
|
+
* Tweak ripl support
|
51
|
+
* Allow override of :hirb_number thanks to asanghi.
|
52
|
+
* Fix Hirb.add_view to work with class which inherits Hash
|
53
|
+
|
54
|
+
== 0.3.5
|
55
|
+
* Add ripl support
|
56
|
+
* Fix Formatter#determine_output_class for IO and Hash
|
57
|
+
* Remove :output_method option for Hirb.enable
|
58
|
+
* Allow rubygems 1.3.5
|
59
|
+
|
60
|
+
== 0.3.4
|
61
|
+
* Added auto format of array-like objects i.e. ActiveRecord::Relation and Set.
|
62
|
+
* Fixed bug when Hirb::Console#table is used without Hirb enabled.
|
63
|
+
* Fixed bug when hirb is running within cron and uses tput.
|
64
|
+
|
65
|
+
== 0.3.3
|
66
|
+
* Added ignore_errors option to ignore view errors and continue with original view.
|
67
|
+
* Added support for array menu items.
|
68
|
+
* Added support to ObjectTable for objects with an undefined :send method.
|
69
|
+
|
70
|
+
== 0.3.2
|
71
|
+
* Added irb autocompletions for bond.
|
72
|
+
* Fixed tests for ruby 1.9.
|
73
|
+
* Changed tests to use bacon.
|
74
|
+
* Removed jeweler in Rakefile and pointless $LOAD_PATH manipulation.
|
75
|
+
|
76
|
+
== 0.3.1
|
77
|
+
* Bug fix on DynamicView.class_to_method to allow overrides of default views.
|
78
|
+
* Modified mongo_mapper view to have _id first.
|
79
|
+
|
80
|
+
== 0.3.0
|
81
|
+
* Added dynamic views.
|
82
|
+
* Added default table views for the following database classes/modules:
|
83
|
+
CouchFoo::Base, CouchPotato::Persistence, CouchRest::ExtendedDocument,
|
84
|
+
DBI::Row, DataMapper::Resource, Friendly::Document, MongoMapper::Document, MongoMapper::EmbeddedDocument,
|
85
|
+
Mongoid::Document, Ripple::Document and Sequel::Model.
|
86
|
+
* Added Hirb.add_view and Hirb.add_dynamic_view for easier view manipulation.
|
87
|
+
* Added :multi_line_nodes option for Tree.
|
88
|
+
* Fixed :change_fields option bug in Table.
|
89
|
+
* Fixed no headers and nil fields bug in Table.
|
90
|
+
* Removed deprecations in Hirb.config_file + View.enable.
|
91
|
+
* Removed Views classes and View.format_class.
|
92
|
+
* Removed :return_rows option for Table.
|
93
|
+
|
94
|
+
== 0.2.10
|
95
|
+
* Added multiple options to Menu, most importantly :two_d and :action.
|
96
|
+
* Improved table resizing algorithm.
|
97
|
+
* Added merging of configs for multiple Hirb.enable calls.
|
98
|
+
* Added :max_fields, :hide_empty, :delete_callbacks, :resize, :header_filter
|
99
|
+
and :return_rows options to Table.
|
100
|
+
* Added escaping for \t and \r in Table.
|
101
|
+
* Renamed Table's :no_newlines option to :escape_special_chars.
|
102
|
+
* Removed Table's :field_lengths option.
|
103
|
+
* Removed Menu's :validate_one option.
|
104
|
+
* Bug fix for table header of a basic array.
|
105
|
+
* Deprecating Hirb.config_file + View.enable in next release.
|
106
|
+
|
107
|
+
== 0.2.9
|
108
|
+
* Added newline filtering and :no_newlines option for table helper.
|
109
|
+
* Added default filters for hashes that have hash values.
|
110
|
+
* Bug fix for deprecated to_a call.
|
111
|
+
|
112
|
+
== 0.2.8
|
113
|
+
* Added callbacks to Hirb::Helpers::Table.
|
114
|
+
* Added :change_fields option to Hirb::Helpers::Table.
|
115
|
+
* Added terminal size detection for jruby.
|
116
|
+
* Bug fix for paging long outputs.
|
117
|
+
* Bug fix to make unexpected hirb rendering errors more clear.
|
118
|
+
|
119
|
+
== 0.2.7
|
120
|
+
* 2 ruby 1.9 bug fixes.
|
121
|
+
* Bug fix in :fields of Hirb::Helpers::ObjectTable.
|
122
|
+
* Made :class option in Hirb::Formatter friendlier to external apps.
|
123
|
+
|
124
|
+
== 0.2.6
|
125
|
+
* Added :description option and added proc ability to :children_method option for helpers.
|
126
|
+
* Bug fix for no ENV['HOME'] on Windows.
|
127
|
+
* Bug fix on unaliasing output_method.
|
128
|
+
* Bug fix on multiple renders of vertical table.
|
129
|
+
|
130
|
+
== 0.2.5
|
131
|
+
* Added ability to use Hirb.enable with non-irb ruby shells.
|
132
|
+
* Helper configs now recursively merge when inheriting from others via :ancestor option.
|
133
|
+
|
134
|
+
== 0.2.4
|
135
|
+
* Bug fix on UTF-8 support.
|
136
|
+
|
137
|
+
== 0.2.3
|
138
|
+
* Added UTF-8 support for Ruby 1.8.x
|
139
|
+
* Added :all_fields option to Table helper.
|
140
|
+
|
141
|
+
== 0.2.2
|
142
|
+
* Added a friendlier default (a vertical table) to incorrectly configured tables.
|
143
|
+
* Added vertical table helper thanks to chrononaut.
|
144
|
+
* Added detection of :select option from ActiveRecord queries in ActiveRecordTable helper.
|
145
|
+
* Added handling anything that responds to :to_a in AutoTable helper.
|
146
|
+
|
147
|
+
== 0.2.1
|
148
|
+
* Fixed typo in Hirb::Console.view
|
149
|
+
|
150
|
+
== 0.2.0
|
151
|
+
* Major refactoring with bug fixes and better tests.
|
152
|
+
* Improved table algorithm to ensure that tables don't wrap.
|
153
|
+
* Added a pager which detects if output should be paged, Hirb::Pager.
|
154
|
+
* Added a selection menu, Hirb::Menu
|
155
|
+
* Following API changes: Hirb::Helpers::Table.max_width removed and config files don't use
|
156
|
+
the :view key anymore.
|
157
|
+
== 0.1.2
|
158
|
+
* Added tree views.
|
159
|
+
* Added output_method option to Hirb::View.render_output.
|
160
|
+
|
161
|
+
== 0.1.1
|
162
|
+
* Fixed bug when rendering table with many fields.
|
163
|
+
|
164
|
+
== 0.1.0
|
165
|
+
* Initial release
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Thanks for trying out this project! [See here for contribution guidelines.](http://tagaholic.me/contributing.html)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2010 Gabriel Horner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
To read a linked version of this README, {click here}[http://tagaholic.me/hirb/doc/].
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Hirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output.
|
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
|
+
views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options
|
8
|
+
for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems
|
9
|
+
i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager
|
10
|
+
only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer
|
11
|
+
{two dimensional menus}[http://tagaholic.me/2010/02/16/two-dimensional-console-menus-with-hirb.html].
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
Install the gem with:
|
16
|
+
|
17
|
+
gem install hirb
|
18
|
+
|
19
|
+
For people using full-width unicode characters, install {hirb-unicode}[https://github.com/miaout17/hirb-unicode]:
|
20
|
+
|
21
|
+
gem install hirb-unicode
|
22
|
+
|
23
|
+
== View Tutorials
|
24
|
+
|
25
|
+
* To create and configure views, see Hirb::View or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/View.html].
|
26
|
+
* To create dynamic views, see Hirb::DynamicView or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/DynamicView.html].
|
27
|
+
|
28
|
+
== Printing Ascii Tables
|
29
|
+
|
30
|
+
To print ascii tables from an array of arrays, hashes or any objects:
|
31
|
+
|
32
|
+
puts Hirb::Helpers::AutoTable.render(ARRAY_OF_OBJECTS)
|
33
|
+
|
34
|
+
Hirb will intelligently pick up on field names from an array of hashes and create properly-aligned
|
35
|
+
fields from an array of arrays. See
|
36
|
+
{here}[http://tagaholic.me/2009/10/15/boson-and-hirb-interactions.html#hirbs_handy_tables] for examples.
|
37
|
+
|
38
|
+
== Rails Example
|
39
|
+
|
40
|
+
Let's load and enable the view framework:
|
41
|
+
$ rails console
|
42
|
+
Loading local environment (Rails 3.0.3)
|
43
|
+
>> require 'hirb'
|
44
|
+
=> true
|
45
|
+
>> Hirb.enable
|
46
|
+
=> nil
|
47
|
+
|
48
|
+
The default configuration provides table views for ActiveRecord::Base descendants.
|
49
|
+
If a class isn't configured, Hirb reverts to irb's default echo mode.
|
50
|
+
>> Hirb::Formatter.dynamic_config['ActiveRecord::Base']
|
51
|
+
=> {:class=>Hirb::Helpers::AutoTable, :ancestor=>true}
|
52
|
+
|
53
|
+
# Tag is a model class and descendant of ActiveRecord::Base
|
54
|
+
>> Tag.last
|
55
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
56
|
+
| id | created_at | description | name | namespace | predicate | value |
|
57
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
58
|
+
| 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml |
|
59
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
60
|
+
1 row in set
|
61
|
+
|
62
|
+
>> Hirb::Formatter.dynamic_config['String']
|
63
|
+
=> nil
|
64
|
+
>> 'plain ol irb'
|
65
|
+
=> 'plain ol irb'
|
66
|
+
>> Hirb::Formatter.dynamic_config['Symbol']
|
67
|
+
=> nil
|
68
|
+
>> :blah
|
69
|
+
=> :blah
|
70
|
+
|
71
|
+
From above you can see there are no views configured for a String or a Symbol so Hirb defaults to
|
72
|
+
irb's echo mode. On the other hand, Tag has a view thanks to being a descendant of ActiveRecord::Base
|
73
|
+
and there being an :ancestor option.
|
74
|
+
|
75
|
+
Having seen hirb display views based on an output object's class, let's see it handle an array of objects:
|
76
|
+
|
77
|
+
>> Tag.all :limit=>3, :order=>"id DESC"
|
78
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
79
|
+
| id | created_at | description | name | namespace | predicate | value |
|
80
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
81
|
+
| 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml |
|
82
|
+
| 906 | 2009-03-06 08:47:04 UTC | | gem:tags=nomonkey | gem | tags | nomonkey |
|
83
|
+
| 905 | 2009-03-04 00:30:10 UTC | | article:tags=ruby | article | tags | ruby |
|
84
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
85
|
+
3 rows in set
|
86
|
+
|
87
|
+
At any time you can disable Hirb if you really like irb's lovely echo mode:
|
88
|
+
>> Hirb.disable
|
89
|
+
=> nil
|
90
|
+
>> Tag.all :limit=>3, :order=>"id DESC"
|
91
|
+
=> [#<Tag id: 907, name: "gem:tags=yaml", description: nil, created_at: "2009-03-06 21:10:41",
|
92
|
+
namespace: "gem", predicate: "tags", value: "yaml">, #<Tag id: 906, name: "gem:tags=nomonkey",
|
93
|
+
description: nil, created_at: "2009-03-06 08:47:04", namespace: "gem", predicate: "tags", value:
|
94
|
+
"nomonkey">, #<Tag id: 905, name: "article:tags=ruby", description: nil, created_at: "2009-03-04
|
95
|
+
00:30:10", namespace: "article", predicate: "tags", value: "ruby">]
|
96
|
+
|
97
|
+
== Views: Anytime, Anywhere
|
98
|
+
While preconfigured tables are great for database records, sometimes you just want to create
|
99
|
+
tables/views for any output object:
|
100
|
+
|
101
|
+
#These examples don't need to have Hirb::View enabled.
|
102
|
+
>> Hirb.disable
|
103
|
+
=> nil
|
104
|
+
|
105
|
+
# Imports table() and view()
|
106
|
+
>> extend Hirb::Console
|
107
|
+
=> main
|
108
|
+
|
109
|
+
# Create a unicode table
|
110
|
+
>> table [[:a, :b, :c]], :unicode => true
|
111
|
+
┌───┬───┬───┐
|
112
|
+
│ 0 │ 1 │ 2 │
|
113
|
+
├───┼───┼───┤
|
114
|
+
│ a ╎ b ╎ c │
|
115
|
+
└───┴───┴───┘
|
116
|
+
1 row in set
|
117
|
+
|
118
|
+
# Creates github-markdown
|
119
|
+
>> table [[:a, :b, :c]], :markdown => true
|
120
|
+
| 0 | 1 | 2 |
|
121
|
+
|---|---|---|
|
122
|
+
| a | b | c |
|
123
|
+
|
124
|
+
# Create a table of Dates comparing them with different formats.
|
125
|
+
>> table [Date.today, Date.today.next_month], :fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
126
|
+
+------------+--------+-----------+-------+--------------------------+
|
127
|
+
| to_s | ld | ajd | amjd | asctime |
|
128
|
+
+------------+--------+-----------+-------+--------------------------+
|
129
|
+
| 2009-03-11 | 155742 | 4909803/2 | 54901 | Wed Mar 11 00:00:00 2009 |
|
130
|
+
| 2009-04-11 | 155773 | 4909865/2 | 54932 | Sat Apr 11 00:00:00 2009 |
|
131
|
+
+------------+--------+-----------+-------+--------------------------+
|
132
|
+
2 rows in set
|
133
|
+
|
134
|
+
# Same table as the previous method. However view() will be able to call any helper.
|
135
|
+
>> view [Date.today, Date.today.next_month], :class=>:object_table,
|
136
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
137
|
+
|
138
|
+
If these console methods weren't convenient enough, try:
|
139
|
+
|
140
|
+
# Imports view() to all objects.
|
141
|
+
>> require 'hirb/import_object'
|
142
|
+
=> true
|
143
|
+
# Yields same table as above examples.
|
144
|
+
>> [Date.today, Date.today.next_month].view :class=>:object_table,
|
145
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
146
|
+
|
147
|
+
Although views by default are printed to STDOUT, they can be easily modified to write anywhere:
|
148
|
+
# Setup views to write to file 'console.log'.
|
149
|
+
>> Hirb::View.render_method = lambda {|output| File.open("console.log", 'w') {|f| f.write(output) } }
|
150
|
+
|
151
|
+
# Writes to file with same table output as above example.
|
152
|
+
>> view [Date.today, Date.today.next_month], :class=>:object_table,
|
153
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
154
|
+
|
155
|
+
# Doesn't write to file because Symbol doesn't have a view and thus defaults to irb's echo mode.
|
156
|
+
>> :blah
|
157
|
+
=> :blah
|
158
|
+
|
159
|
+
# Go back to printing Hirb views to STDOUT.
|
160
|
+
>> Hirb::View.reset_render_method
|
161
|
+
|
162
|
+
== Pager
|
163
|
+
|
164
|
+
Hirb has both pager and formatter functionality enabled by default. Note - if you copy and paste
|
165
|
+
into your ruby console and think that one of your lines will kick off the pager, be aware that subsequent
|
166
|
+
characters will go to your pager and could cause side effects like saving a file.
|
167
|
+
|
168
|
+
If you want to turn off the functionality of either pager or formatter, pass that in at startup:
|
169
|
+
|
170
|
+
Hirb.enable :pager=>false
|
171
|
+
Hirb.enable :formatter=>false
|
172
|
+
|
173
|
+
or toggle their state at runtime:
|
174
|
+
|
175
|
+
Hirb::View.toggle_pager
|
176
|
+
Hirb::View.toggle_formatter
|
177
|
+
|
178
|
+
== Sharing Helpers and Views
|
179
|
+
If you have tested helpers you'd like to share, fork Hirb and put them under lib/hirb/helpers. To share
|
180
|
+
views for certain classes, put them under lib/hirb/views. Please submit views for gems that have a nontrivial
|
181
|
+
number of users.
|
182
|
+
|
183
|
+
== Limitations
|
184
|
+
If using Wirble and irb, you should call Hirb after it since they both override irb's default output.
|
185
|
+
|
186
|
+
== Motivation
|
187
|
+
Table code from http://gist.github.com/72234 and {my console app's needs}[http://github.com/cldwalker/tag-tree].
|
188
|
+
|
189
|
+
== Credits
|
190
|
+
* Chrononaut for vertical table helper.
|
191
|
+
* janlelis for unicode table helper.
|
192
|
+
* technogeeky and FND for markdown table helper.
|
193
|
+
* hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall, maxmeyer, jimjh, ddoherty03,
|
194
|
+
rochefort and joshua for patches.
|
195
|
+
|
196
|
+
== Bugs/Issues
|
197
|
+
Please report them {on github}[http://github.com/cldwalker/hirb/issues].
|
198
|
+
|
199
|
+
== Contributing
|
200
|
+
{See here}[http://tagaholic.me/contributing.html]
|
201
|
+
|
202
|
+
== Links
|
203
|
+
* http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html
|
204
|
+
* http://tagaholic.me/2009/03/18/ruby-class-trees-rails-plugin-trees-with-hirb.html
|
205
|
+
* http://tagaholic.me/2009/06/19/page-irb-output-and-improve-ri-with-hirb.html
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Build the gem"
|
9
|
+
task :gem=>:gemspec do
|
10
|
+
sh "gem build .gemspec"
|
11
|
+
FileUtils.mkdir_p 'pkg'
|
12
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Install the gem locally"
|
16
|
+
task :install => :gem do
|
17
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Generate the gemspec"
|
21
|
+
task :generate do
|
22
|
+
puts gemspec.to_ruby
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Validate the gemspec"
|
26
|
+
task :gemspec do
|
27
|
+
gemspec.validate
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run tests'
|
31
|
+
task :test do |t|
|
32
|
+
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|