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.
@@ -1,29 +1,30 @@
1
- *SVN*
1
+ == master
2
2
 
3
- *0.0.5* (June 22nd, 2008)
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
- *0.0.4* (June 15th, 2008)
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
- *0.0.3* (June 1st, 2008)
17
+ == 0.0.3 / 2008-06-01
14
18
 
15
19
  * Remove dependency on set_or_append
16
20
 
17
- *0.0.2* (May 5th, 2008)
21
+ == 0.0.2 / 2008-05-05
18
22
 
19
23
  * Updated documentation
20
24
 
21
- *0.0.1* (August 18th, 2007)
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
File without changes
@@ -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://dev.pluginaweek.org/browser/trunk/table_helper
17
+ * http://github.com/pluginaweek/table_helper
18
18
 
19
19
  Source
20
20
 
21
- * http://svn.pluginaweek.org/trunk/table_helper
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 options. You should only use
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://wiki.pluginaweek.org/Plugin_test_helper]
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
- PKG_NAME = 'table_helper'
7
- PKG_VERSION = '0.0.5'
8
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
- RUBY_FORGE_PROJECT = 'pluginaweek'
10
-
11
- desc 'Default: run unit tests.'
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 'Test the table_helper plugin.'
26
+ desc "Test the #{spec.name} plugin."
15
27
  Rake::TestTask.new(:test) do |t|
16
28
  t.libs << 'lib'
17
- t.pattern = 'test/**/*_test.rb'
29
+ t.test_files = spec.test_files
18
30
  t.verbose = true
19
31
  end
20
32
 
21
- desc 'Generate documentation for the table_helper plugin.'
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 = 'TableHelper'
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', "#{PKG_FILE_NAME}.gem").upload
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/#{PKG_NAME}", 'rdoc').upload
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( gem tgz zip ).each do |ext|
75
- file = "pkg/#{PKG_FILE_NAME}.#{ext}"
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(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
86
+ ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
79
87
  end
80
88
  end
@@ -1,182 +1,180 @@
1
1
  require 'table_helper/collection_table'
2
2
 
3
- module PluginAWeek #:nodoc:
4
- # Provides a set of methods for turning a collection into a table.
5
- #
6
- # == Basic Example
7
- #
8
- # This example shows the most basic usage of +collection_table+ which takes
9
- # information about a collection, the objects in them, the columns defined
10
- # for the class, and generates a table based on that.
11
- #
12
- # Support you have a table generated by a migration like so:
13
- #
14
- # class CreatePeople < ActiveRecord::Base
15
- # def self.up
16
- # create_table do |t|
17
- # t.string :first_name
18
- # t.string :last_name
19
- # t.integer :company_id
20
- # t.string :role
21
- # end
22
- # end
23
- # end
24
- #
25
- # ...then invoking the helper:
26
- #
27
- # <%= collection_table Person.find(:all) %>
28
- #
29
- # ...is compiled to (formatted here for the sake of sanity):
30
- #
31
- # <table cellpadding="0" cellspacing="0">
32
- # <thead>
33
- # <tr>
34
- # <th class="first_name" scope="col">First Name</th>
35
- # <th class="last_name" scope="col">Last Name</th>
36
- # <th class="company_id" scope="col">Company</th>
37
- # <th class="role" scope="col">Role</th>
38
- # </tr>
39
- # </thead>
40
- # <tbody>
41
- # <tr class="row">
42
- # <td class="first_name">John</td>
43
- # <td class="last_name">Doe</td>
44
- # <td class="company_id">1</td>
45
- # <td class="role">President</td>
46
- # </tr>
47
- # <tr class="row">
48
- # <td class="first_name">Jane</td>
49
- # <td class="last_name">Doe</td>
50
- # <td class="company_id">1</td>
51
- # <td class="role">Vice-President</td>
52
- # </tr>
53
- # </tbody>
54
- # <table>
55
- #
56
- # == Advanced Example
57
- #
58
- # This example below shows how +collection_table+ can be customized to show
59
- # specific headers, content, and footers.
60
- #
61
- # <%=
62
- # collection_table(@posts, {}, :id => 'posts', :class => 'summary') do |header, body|
63
- # header.column :title
64
- # header.column :category
65
- # header.column :author
66
- # header.column :publish_date, 'Date<br \>Published'
67
- # header.column :num_comments, '# Comments'
68
- # header.column :num_trackbacks, '# Trackbacks'
69
- #
70
- # body.alternate = true
71
- # body.build do |row, post, index|
72
- # row.category post.category.name
73
- # row.author post.author.name
74
- # row.publish_date time_ago_in_words(post.published_on)
75
- # row.num_comments post.comments.empty? ? '-' : post.comments.size
76
- # row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size
77
- # end
78
- # end
79
- # %>
80
- #
81
- # ...is compiled to (formatted here for the sake of sanity):
82
- #
83
- # <table cellpadding="0" cellspacing="0" class="summary" id="posts">
84
- # <thead>
85
- # <tr>
86
- # <th class="title" scope="col">Title</th>
87
- # <th class="category" scope="col">Category</th>
88
- # <th class="author" scope="col">Author</th>
89
- # <th class="publish_date" scope="col">Date<br \>Published</th>
90
- # <th class="num_comments" scope="col"># Comments</th>
91
- # <th class="num_trackbacks" scope="col"># Trackbacks</th>
92
- # </tr>
93
- # </thead>
94
- # <tbody class="alternate">
95
- # <tr class="row">
96
- # <td class="title">Open-source projects: The good, the bad, and the ugly</td>
97
- # <td class="category">General</td>
98
- # <td class="author">John Doe</td>
99
- # <td class="publish_date">23 days</td>
100
- # <td class="num_comments">-</td>
101
- # <td class="num_trackbacks">-</td>
102
- # </tr>
103
- # <tr class="row alternate">
104
- # <td class="title">5 reasons you should care about Rails</td>
105
- # <td class="category">Rails</td><td class="author">John Q. Public</td>
106
- # <td class="publish_date">21 days</td>
107
- # <td class="num_comments">-</td>
108
- # <td class="num_trackbacks">-</td>
109
- # </tr>
110
- # <tr class="row">
111
- # <td class="title">Deprecation: Stop digging yourself a hole</td>
112
- # <td class="category">Rails</td>
113
- # <td class="author">Jane Doe</td>
114
- # <td class="publish_date">17 days</td>
115
- # <td class="num_comments">-</td>
116
- # <td class="num_trackbacks">-</td>
117
- # </tr>
118
- # <tr class="row alternate">
119
- # <td class="title">Jumpstart your Rails career at RailsConf 2007</td>
120
- # <td class="category">Conferences</td>
121
- # <td class="author">Jane Doe</td>
122
- # <td class="publish_date">4 days</td>
123
- # <td class="num_comments">-</td>
124
- # <td class="num_trackbacks">-</td>
125
- # </tr>
126
- # <tr class="row">
127
- # <td class="title">Getting some REST</td>
128
- # <td class="category">Rails</td>
129
- # <td class="author">John Doe</td>
130
- # <td class="publish_date">about 18 hours</td>
131
- # <td class="num_comments">-</td>
132
- # <td class="num_trackbacks">-</td>
133
- # </tr>
134
- # </tbody>
135
- # </table>
136
- #
137
- # == Creating footers
138
- #
139
- # Footers allow you to show some sort of summary information based on the
140
- # data displayed in the body of the table. Below is an example:
141
- #
142
- # <%
143
- # collection_table(@posts, :footer => true) do |header, body, footer|
144
- # header.column :title
145
- # header.column :category
146
- # header.column :author
147
- # header.column :publish_date, 'Date<br \>Published'
148
- # header.column :num_comments, '# Comments'
149
- # header.column :num_trackbacks, '# Trackbacks'
150
- #
151
- # body.alternate = true
152
- # body.build do |row, post, index|
153
- # row.category post.category.name
154
- # row.author post.author.name
155
- # row.publish_date time_ago_in_words(post.published_on)
156
- # row.num_comments post.comments.empty? ? '-' : post.comments.size
157
- # row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size
158
- # end
159
- #
160
- # footer.cell :num_comments, @posts.inject(0) {|sum, post| sum += post.comments.size}
161
- # footer.cell :num_trackbacks, @posts.inject(0) {|sum, post| sum += post.trackbacks.size}
162
- # end
163
- # %>
164
- module TableHelper
165
- # Creates a new table based on the given collection
166
- #
167
- # Configuration options:
168
- #
169
- # * +class+ - Specify the type of objects expected in the collection if it can't be guessed from its contents.
170
- # * +header+ - Specify if a header (thead) should be built into the table. Default is true.
171
- # * +footer+ - Specify if a footer (tfoot) should be built into the table. Default is false.
172
- def collection_table(collection, options = {}, html_options = {}, &block)
173
- table = CollectionTable.new(collection, options, html_options)
174
- table.build(&block)
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 PluginAWeek::TableHelper
179
+ helper TableHelper
182
180
  end