table_helper 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGELOG → CHANGELOG.rdoc} +11 -10
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/{README → README.rdoc} +9 -9
- data/Rakefile +44 -36
- data/lib/table_helper.rb +173 -175
- data/lib/table_helper/body.rb +102 -105
- data/lib/table_helper/body_row.rb +58 -74
- data/lib/table_helper/cell.rb +44 -46
- data/lib/table_helper/collection_table.rb +53 -49
- data/lib/table_helper/footer.rb +36 -38
- data/lib/table_helper/header.rb +138 -140
- data/lib/table_helper/html_element.rb +39 -41
- data/lib/table_helper/row.rb +85 -87
- data/test/{table_helper_test.rb → helpers/table_helper_test.rb} +5 -5
- data/test/test_helper.rb +4 -7
- data/test/{body_row_test.rb → unit/body_row_test.rb} +13 -13
- data/test/{body_test.rb → unit/body_test.rb} +35 -35
- data/test/{cell_test.rb → unit/cell_test.rb} +7 -7
- data/test/{collection_table_test.rb → unit/collection_table_test.rb} +31 -31
- data/test/{footer_test.rb → unit/footer_test.rb} +12 -12
- data/test/{header_builder_test.rb → unit/header_builder_test.rb} +8 -8
- data/test/{header_test.rb → unit/header_test.rb} +36 -36
- data/test/{html_element_test.rb → unit/html_element_test.rb} +8 -8
- data/test/{row_builder_test.rb → unit/row_builder_test.rb} +9 -9
- data/test/{row_test.rb → unit/row_test.rb} +11 -11
- metadata +37 -35
@@ -1,29 +1,30 @@
|
|
1
|
-
|
1
|
+
== master
|
2
2
|
|
3
|
-
|
3
|
+
== 0.1.0 / 2008-12-14
|
4
|
+
|
5
|
+
* Remove the PluginAWeek namespace
|
6
|
+
* Update tests to use ActionView::TestCase
|
7
|
+
|
8
|
+
== 0.0.5 / 2008-06-22
|
4
9
|
|
5
10
|
* Remove log files from gems
|
6
11
|
|
7
|
-
|
12
|
+
== 0.0.4 / 2008-06-15
|
8
13
|
|
9
14
|
* Support cell/column names that conflict with existing method names on the Row/Header classes
|
10
|
-
|
11
15
|
* Avoid string evaluation for dynamic methods
|
12
16
|
|
13
|
-
|
17
|
+
== 0.0.3 / 2008-06-01
|
14
18
|
|
15
19
|
* Remove dependency on set_or_append
|
16
20
|
|
17
|
-
|
21
|
+
== 0.0.2 / 2008-05-05
|
18
22
|
|
19
23
|
* Updated documentation
|
20
24
|
|
21
|
-
|
25
|
+
== 0.0.1 / 2007-08-18
|
22
26
|
|
23
27
|
* Add README documentation
|
24
|
-
|
25
28
|
* Add gem dependency on set_or_append
|
26
|
-
|
27
29
|
* Refactor test method names
|
28
|
-
|
29
30
|
* Convert dos newlines to unix newlines
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/{README → README.rdoc}
RENAMED
@@ -4,21 +4,21 @@
|
|
4
4
|
|
5
5
|
== Resources
|
6
6
|
|
7
|
-
Wiki
|
8
|
-
|
9
|
-
* http://wiki.pluginaweek.org/Table_helper
|
10
|
-
|
11
7
|
API
|
12
8
|
|
13
9
|
* http://api.pluginaweek.org/table_helper
|
14
10
|
|
11
|
+
Bugs
|
12
|
+
|
13
|
+
* http://pluginaweek.lighthouseapp.com/projects/13290-table_helper
|
14
|
+
|
15
15
|
Development
|
16
16
|
|
17
|
-
* http://
|
17
|
+
* http://github.com/pluginaweek/table_helper
|
18
18
|
|
19
19
|
Source
|
20
20
|
|
21
|
-
*
|
21
|
+
* git://github.com/pluginaweek/table_helper.git
|
22
22
|
|
23
23
|
== Description
|
24
24
|
|
@@ -140,8 +140,8 @@ these types of tables by DRYing much of the html being generated.
|
|
140
140
|
|
141
141
|
=== Caveat Emptor
|
142
142
|
|
143
|
-
See the API for more information on syntax and
|
144
|
-
table_helper if it fits the needs of your application. Remember one of the key
|
143
|
+
See the API for more information on syntax, options, and examples. You should only
|
144
|
+
use table_helper if it fits the needs of your application. Remember one of the key
|
145
145
|
principles of Rails, KISS (Keep It Simple Stupid). table_helper works really
|
146
146
|
well when you need to quickly output several of these types of summary tables.
|
147
147
|
If this is not the case, you may want to stick to using actual html.
|
@@ -149,7 +149,7 @@ If this is not the case, you may want to stick to using actual html.
|
|
149
149
|
== Testing
|
150
150
|
|
151
151
|
Before you can run any tests, the following gem must be installed:
|
152
|
-
* plugin_test_helper[http://
|
152
|
+
* plugin_test_helper[http://github.com/pluginaweek/plugin_test_helper]
|
153
153
|
|
154
154
|
To run against a specific version of Rails:
|
155
155
|
|
data/Rakefile
CHANGED
@@ -3,46 +3,54 @@ require 'rake/rdoctask'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
spec = Gem::Specification.new do |s|
|
7
|
+
s.name = 'table_helper'
|
8
|
+
s.version = '0.1.0'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'Adds a helper method for generating HTML tables from collections'
|
11
|
+
|
12
|
+
s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
|
+
s.require_path = 'lib'
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.test_files = Dir['test/**/*_test.rb']
|
16
|
+
|
17
|
+
s.author = 'Aaron Pfeifer'
|
18
|
+
s.email = 'aaron@pluginaweek.org'
|
19
|
+
s.homepage = 'http://www.pluginaweek.org'
|
20
|
+
s.rubyforge_project = 'pluginaweek'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Default: run all tests.'
|
12
24
|
task :default => :test
|
13
25
|
|
14
|
-
desc
|
26
|
+
desc "Test the #{spec.name} plugin."
|
15
27
|
Rake::TestTask.new(:test) do |t|
|
16
28
|
t.libs << 'lib'
|
17
|
-
t.
|
29
|
+
t.test_files = spec.test_files
|
18
30
|
t.verbose = true
|
19
31
|
end
|
20
32
|
|
21
|
-
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
namespace :test do
|
36
|
+
desc "Test the #{spec.name} plugin with Rcov."
|
37
|
+
Rcov::RcovTask.new(:rcov) do |t|
|
38
|
+
t.libs << 'lib'
|
39
|
+
t.test_files = spec.test_files
|
40
|
+
t.rcov_opts << '--exclude="^(?!lib/)"'
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Generate documentation for the #{spec.name} plugin."
|
22
48
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
49
|
rdoc.rdoc_dir = 'rdoc'
|
24
|
-
rdoc.title =
|
50
|
+
rdoc.title = spec.name
|
25
51
|
rdoc.template = '../rdoc_template.rb'
|
26
52
|
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
-
rdoc.rdoc_files.include('README')
|
28
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
-
end
|
30
|
-
|
31
|
-
spec = Gem::Specification.new do |s|
|
32
|
-
s.name = PKG_NAME
|
33
|
-
s.version = PKG_VERSION
|
34
|
-
s.platform = Gem::Platform::RUBY
|
35
|
-
s.summary = 'Adds a helper method for generating HTML tables from collections'
|
36
|
-
|
37
|
-
s.files = FileList['{lib,test}/**/*'].to_a - FileList['test/app_root/log/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
38
|
-
s.require_path = 'lib'
|
39
|
-
s.autorequire = 'table_helper'
|
40
|
-
s.has_rdoc = true
|
41
|
-
s.test_files = Dir['test/**/*_test.rb']
|
42
|
-
|
43
|
-
s.author = 'Aaron Pfeifer'
|
44
|
-
s.email = 'aaron@pluginaweek.org'
|
45
|
-
s.homepage = 'http://www.pluginaweek.org'
|
53
|
+
rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb')
|
46
54
|
end
|
47
55
|
|
48
56
|
Rake::GemPackageTask.new(spec) do |p|
|
@@ -51,14 +59,14 @@ Rake::GemPackageTask.new(spec) do |p|
|
|
51
59
|
p.need_zip = true
|
52
60
|
end
|
53
61
|
|
54
|
-
desc 'Publish the beta gem'
|
62
|
+
desc 'Publish the beta gem.'
|
55
63
|
task :pgem => [:package] do
|
56
|
-
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{
|
64
|
+
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
|
57
65
|
end
|
58
66
|
|
59
|
-
desc 'Publish the API documentation'
|
67
|
+
desc 'Publish the API documentation.'
|
60
68
|
task :pdoc => [:rdoc] do
|
61
|
-
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{
|
69
|
+
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
|
62
70
|
end
|
63
71
|
|
64
72
|
desc 'Publish the API docs and gem'
|
@@ -71,10 +79,10 @@ task :release => [:gem, :package] do
|
|
71
79
|
ruby_forge = RubyForge.new.configure
|
72
80
|
ruby_forge.login
|
73
81
|
|
74
|
-
%w(
|
75
|
-
file = "pkg/#{
|
82
|
+
%w(gem tgz zip).each do |ext|
|
83
|
+
file = "pkg/#{spec.name}-#{spec.version}.#{ext}"
|
76
84
|
puts "Releasing #{File.basename(file)}..."
|
77
85
|
|
78
|
-
ruby_forge.add_release(
|
86
|
+
ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
|
79
87
|
end
|
80
88
|
end
|
data/lib/table_helper.rb
CHANGED
@@ -1,182 +1,180 @@
|
|
1
1
|
require 'table_helper/collection_table'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
table.html
|
176
|
-
end
|
3
|
+
# Provides a set of methods for turning a collection into a table.
|
4
|
+
#
|
5
|
+
# == Basic Example
|
6
|
+
#
|
7
|
+
# This example shows the most basic usage of +collection_table+ which takes
|
8
|
+
# information about a collection, the objects in them, the columns defined
|
9
|
+
# for the class, and generates a table based on that.
|
10
|
+
#
|
11
|
+
# Suppose you have a table generated by a migration like so:
|
12
|
+
#
|
13
|
+
# class CreatePeople < ActiveRecord::Base
|
14
|
+
# def self.up
|
15
|
+
# create_table do |t|
|
16
|
+
# t.string :first_name
|
17
|
+
# t.string :last_name
|
18
|
+
# t.integer :company_id
|
19
|
+
# t.string :role
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# ...then invoking the helper within a view:
|
25
|
+
#
|
26
|
+
# <%= collection_table Person.find(:all) %>
|
27
|
+
#
|
28
|
+
# ...is compiled to (formatted here for the sake of sanity):
|
29
|
+
#
|
30
|
+
# <table cellpadding="0" cellspacing="0">
|
31
|
+
# <thead>
|
32
|
+
# <tr>
|
33
|
+
# <th class="first_name" scope="col">First Name</th>
|
34
|
+
# <th class="last_name" scope="col">Last Name</th>
|
35
|
+
# <th class="company_id" scope="col">Company</th>
|
36
|
+
# <th class="role" scope="col">Role</th>
|
37
|
+
# </tr>
|
38
|
+
# </thead>
|
39
|
+
# <tbody>
|
40
|
+
# <tr class="row">
|
41
|
+
# <td class="first_name">John</td>
|
42
|
+
# <td class="last_name">Doe</td>
|
43
|
+
# <td class="company_id">1</td>
|
44
|
+
# <td class="role">President</td>
|
45
|
+
# </tr>
|
46
|
+
# <tr class="row">
|
47
|
+
# <td class="first_name">Jane</td>
|
48
|
+
# <td class="last_name">Doe</td>
|
49
|
+
# <td class="company_id">1</td>
|
50
|
+
# <td class="role">Vice-President</td>
|
51
|
+
# </tr>
|
52
|
+
# </tbody>
|
53
|
+
# <table>
|
54
|
+
#
|
55
|
+
# == Advanced Example
|
56
|
+
#
|
57
|
+
# This example below shows how +collection_table+ can be customized to show
|
58
|
+
# specific headers, content, and footers.
|
59
|
+
#
|
60
|
+
# <%=
|
61
|
+
# collection_table(@posts, {}, :id => 'posts', :class => 'summary') do |header, body|
|
62
|
+
# header.column :title
|
63
|
+
# header.column :category
|
64
|
+
# header.column :author
|
65
|
+
# header.column :publish_date, 'Date<br \>Published'
|
66
|
+
# header.column :num_comments, '# Comments'
|
67
|
+
# header.column :num_trackbacks, '# Trackbacks'
|
68
|
+
#
|
69
|
+
# body.alternate = true
|
70
|
+
# body.build do |row, post, index|
|
71
|
+
# row.category post.category.name
|
72
|
+
# row.author post.author.name
|
73
|
+
# row.publish_date time_ago_in_words(post.published_on)
|
74
|
+
# row.num_comments post.comments.empty? ? '-' : post.comments.size
|
75
|
+
# row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
# %>
|
79
|
+
#
|
80
|
+
# ...is compiled to (formatted here for the sake of sanity):
|
81
|
+
#
|
82
|
+
# <table cellpadding="0" cellspacing="0" class="summary" id="posts">
|
83
|
+
# <thead>
|
84
|
+
# <tr>
|
85
|
+
# <th class="title" scope="col">Title</th>
|
86
|
+
# <th class="category" scope="col">Category</th>
|
87
|
+
# <th class="author" scope="col">Author</th>
|
88
|
+
# <th class="publish_date" scope="col">Date<br \>Published</th>
|
89
|
+
# <th class="num_comments" scope="col"># Comments</th>
|
90
|
+
# <th class="num_trackbacks" scope="col"># Trackbacks</th>
|
91
|
+
# </tr>
|
92
|
+
# </thead>
|
93
|
+
# <tbody class="alternate">
|
94
|
+
# <tr class="row">
|
95
|
+
# <td class="title">Open-source projects: The good, the bad, and the ugly</td>
|
96
|
+
# <td class="category">General</td>
|
97
|
+
# <td class="author">John Doe</td>
|
98
|
+
# <td class="publish_date">23 days</td>
|
99
|
+
# <td class="num_comments">-</td>
|
100
|
+
# <td class="num_trackbacks">-</td>
|
101
|
+
# </tr>
|
102
|
+
# <tr class="row alternate">
|
103
|
+
# <td class="title">5 reasons you should care about Rails</td>
|
104
|
+
# <td class="category">Rails</td><td class="author">John Q. Public</td>
|
105
|
+
# <td class="publish_date">21 days</td>
|
106
|
+
# <td class="num_comments">-</td>
|
107
|
+
# <td class="num_trackbacks">-</td>
|
108
|
+
# </tr>
|
109
|
+
# <tr class="row">
|
110
|
+
# <td class="title">Deprecation: Stop digging yourself a hole</td>
|
111
|
+
# <td class="category">Rails</td>
|
112
|
+
# <td class="author">Jane Doe</td>
|
113
|
+
# <td class="publish_date">17 days</td>
|
114
|
+
# <td class="num_comments">-</td>
|
115
|
+
# <td class="num_trackbacks">-</td>
|
116
|
+
# </tr>
|
117
|
+
# <tr class="row alternate">
|
118
|
+
# <td class="title">Jumpstart your Rails career at RailsConf 2007</td>
|
119
|
+
# <td class="category">Conferences</td>
|
120
|
+
# <td class="author">Jane Doe</td>
|
121
|
+
# <td class="publish_date">4 days</td>
|
122
|
+
# <td class="num_comments">-</td>
|
123
|
+
# <td class="num_trackbacks">-</td>
|
124
|
+
# </tr>
|
125
|
+
# <tr class="row">
|
126
|
+
# <td class="title">Getting some REST</td>
|
127
|
+
# <td class="category">Rails</td>
|
128
|
+
# <td class="author">John Doe</td>
|
129
|
+
# <td class="publish_date">about 18 hours</td>
|
130
|
+
# <td class="num_comments">-</td>
|
131
|
+
# <td class="num_trackbacks">-</td>
|
132
|
+
# </tr>
|
133
|
+
# </tbody>
|
134
|
+
# </table>
|
135
|
+
#
|
136
|
+
# == Creating footers
|
137
|
+
#
|
138
|
+
# Footers allow you to show some sort of summary information based on the
|
139
|
+
# data displayed in the body of the table. Below is an example:
|
140
|
+
#
|
141
|
+
# <%
|
142
|
+
# collection_table(@posts, :footer => true) do |header, body, footer|
|
143
|
+
# header.column :title
|
144
|
+
# header.column :category
|
145
|
+
# header.column :author
|
146
|
+
# header.column :publish_date, 'Date<br \>Published'
|
147
|
+
# header.column :num_comments, '# Comments'
|
148
|
+
# header.column :num_trackbacks, '# Trackbacks'
|
149
|
+
#
|
150
|
+
# body.alternate = true
|
151
|
+
# body.build do |row, post, index|
|
152
|
+
# row.category post.category.name
|
153
|
+
# row.author post.author.name
|
154
|
+
# row.publish_date time_ago_in_words(post.published_on)
|
155
|
+
# row.num_comments post.comments.empty? ? '-' : post.comments.size
|
156
|
+
# row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# footer.cell :num_comments, @posts.inject(0) {|sum, post| sum += post.comments.size}
|
160
|
+
# footer.cell :num_trackbacks, @posts.inject(0) {|sum, post| sum += post.trackbacks.size}
|
161
|
+
# end
|
162
|
+
# %>
|
163
|
+
module TableHelper
|
164
|
+
# Creates a new table based on the objects in the given collection
|
165
|
+
#
|
166
|
+
# Configuration options:
|
167
|
+
#
|
168
|
+
# * +class+ - Specify the type of objects expected in the collection if it can't be guessed from its contents.
|
169
|
+
# * +header+ - Specify if a header (thead) should be built into the table. Default is true.
|
170
|
+
# * +footer+ - Specify if a footer (tfoot) should be built into the table. Default is false.
|
171
|
+
def collection_table(collection, options = {}, html_options = {}, &block)
|
172
|
+
table = CollectionTable.new(collection, options, html_options)
|
173
|
+
table.build(&block)
|
174
|
+
table.html
|
177
175
|
end
|
178
176
|
end
|
179
177
|
|
180
178
|
ActionController::Base.class_eval do
|
181
|
-
helper
|
179
|
+
helper TableHelper
|
182
180
|
end
|