README.rdoc in table_helper-0.1.0 vs README.rdoc in table_helper-0.2.0
- old
+ new
@@ -33,110 +33,121 @@
<%= collection_table Person.find(:all) %>
...is compiled to (formatted here for the sake of sanity):
- <table cellpadding="0" cellspacing="0">
+ <table cellpadding="0" cellspacing="0" class="people ui-collection">
<thead>
<tr>
- <th class="first_name" scope="col">First Name</th>
- <th class="last_name" scope="col">Last Name</th>
- <th class="company_id" scope="col">Company</th>
- <th class="role" scope="col">Role</th>
+ <th class="person-first_name" scope="col">First Name</th>
+ <th class="person-last_name" scope="col">Last Name</th>
+ <th class="person-company_id" scope="col">Company</th>
+ <th class="person-role" scope="col">Role</th>
</tr>
</thead>
<tbody>
- <tr class="row">
- <td class="first_name">John</td>
- <td class="last_name">Doe</td>
- <td class="company_id">1</td>
- <td class="role">President</td>
+ <tr class="person ui-collection-result">
+ <td class="person-first_name">John</td>
+ <td class="person-last_name">Doe</td>
+ <td class="person-company_id">1</td>
+ <td class="person-role">President</td>
</tr>
- <tr class="row">
- <td class="first_name">Jane</td>
- <td class="last_name">Doe</td>
- <td class="company_id">1</td>
- <td class="role">Vice-President</td>
+ <tr class="person ui-collection-result">
+ <td class="person-first_name">Jane</td>
+ <td class="person-last_name">Doe</td>
+ <td class="person-company_id">1</td>
+ <td class="person-role">Vice-President</td>
</tr>
</tbody>
<table>
=== Advanced Example
<%=
- collection_table(@posts, {}, :id => 'posts', :class => 'summary') do |header, body|
- header.column :title
- header.column :category
- header.column :author
- header.column :publish_date, 'Date<br \>Published'
- header.column :num_comments, '# Comments'
- header.column :num_trackbacks, '# Trackbacks'
+ collection_table(@posts, :id => 'posts', :class => 'summary') do |t|
+ t.header :title
+ t.header :category
+ t.header :author
+ t.header :publish_date, 'Date<br \>Published'
+ t.header :num_comments, '# Comments'
+ t.header :num_trackbacks, '# Trackbacks'
- body.alternate = true
- body.build do |row, post, index|
+ t.rows.alternate = :odd
+ t.rows.each do |row, post, index|
+ # Notice there's no need to explicitly define the title
row.category post.category.name
row.author post.author.name
- row.publish_date time_ago_in_words(post.published_on)
+ row.publish_date time_ago_in_words(post.published_at)
row.num_comments post.comments.empty? ? '-' : post.comments.size
row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size
end
+
+ t.footer :num_comments, @posts.inject(0) {|sum, post| sum += post.comments.size}
+ t.footer :num_trackbacks, @posts.inject(0) {|sum, post| sum += post.trackbacks.size}
end
%>
...is compiled to (formatted here for the sake of sanity):
- <table cellpadding="0" cellspacing="0" class="summary" id="posts">
+ <table cellpadding="0" cellspacing="0" class="summary posts ui-collection" id="posts">
<thead>
<tr>
- <th class="title" scope="col">Title</th>
- <th class="category" scope="col">Category</th>
- <th class="author" scope="col">Author</th>
- <th class="publish_date" scope="col">Date<br \>Published</th>
- <th class="num_comments" scope="col"># Comments</th>
- <th class="num_trackbacks" scope="col"># Trackbacks</th>
+ <th class="post-title" scope="col">Title</th>
+ <th class="post-category" scope="col">Category</th>
+ <th class="post-author" scope="col">Author</th>
+ <th class="post-publish_date" scope="col">Date<br \>Published</th>
+ <th class="post-num_comments" scope="col"># Comments</th>
+ <th class="post-num_trackbacks" scope="col"># Trackbacks</th>
</tr>
</thead>
- <tbody class="alternate">
- <tr class="row">
- <td class="title">Open-source projects: The good, the bad, and the ugly</td>
- <td class="category">General</td>
- <td class="author">John Doe</td>
- <td class="publish_date">23 days</td>
- <td class="num_comments">-</td>
- <td class="num_trackbacks">-</td>
+ <tbody>
+ <tr class="post ui-collection-result">
+ <td class="post-title">Open-source projects: The good, the bad, and the ugly</td>
+ <td class="post-category">General</td>
+ <td class="post-author">John Doe</td>
+ <td class="post-publish_date">23 days</td>
+ <td class="post-num_comments">-</td>
+ <td class="post-num_trackbacks">-</td>
</tr>
- <tr class="row alternate">
- <td class="title">5 reasons you should care about Rails</td>
- <td class="category">Rails</td><td class="author">John Q. Public</td>
- <td class="publish_date">21 days</td>
- <td class="num_comments">-</td>
- <td class="num_trackbacks">-</td>
+ <tr class="post ui-collection-result ui-state-alternate">
+ <td class="post-title">5 reasons you should care about Rails</td>
+ <td class="post-category">Rails</td>
+ <td class="post-author">John Q. PUblic</td>
+ <td class="post-publish_date">21 days</td>
+ <td class="post-num_comments">-</td>
+ <td class="post-num_trackbacks">-</td>
</tr>
- <tr class="row">
- <td class="title">Deprecation: Stop digging yourself a hole</td>
- <td class="category">Rails</td>
- <td class="author">Jane Doe</td>
- <td class="publish_date">17 days</td>
- <td class="num_comments">-</td>
- <td class="num_trackbacks">-</td>
+ <tr class="post ui-collection-result">
+ <td class="post-title">Deprecation: Stop digging yourself a hole</td>
+ <td class="post-category">Rails</td>
+ <td class="post-author">Jane Doe</td>
+ <td class="post-publish_date">17 days</td>
+ <td class="post-num_comments">-</td>
+ <td class="post-num_trackbacks">-</td>
</tr>
- <tr class="row alternate">
- <td class="title">Jumpstart your Rails career at RailsConf 2007</td>
- <td class="category">Conferences</td>
- <td class="author">Jane Doe</td>
- <td class="publish_date">4 days</td>
- <td class="num_comments">-</td>
- <td class="num_trackbacks">-</td>
+ <tr class="post ui-collection-result ui-state-alternate">
+ <td class="post-title">Jumpstart your Rails career at RailsConf 2007</td>
+ <td class="post-category">Conferences</td>
+ <td class="post-author">Jane Doe</td>
+ <td class="post-publish_date">4 days</td>
+ <td class="post-num_comments">-</td>
+ <td class="post-num_trackbacks">-</td>
</tr>
- <tr class="row">
- <td class="title">Getting some REST</td>
- <td class="category">Rails</td>
- <td class="author">John Doe</td>
- <td class="publish_date">about 18 hours</td>
- <td class="num_comments">-</td>
- <td class="num_trackbacks">-</td>
+ <tr class="post ui-collection-result">
+ <td class="post-title">Getting some REST</td>
+ <td class="post-category">Rails</td>
+ <td class="post-author">John Doe</td>
+ <td class="post-publish_date">about 18 hours</td>
+ <td class="post-num_comments">-</td>
+ <td class="post-num_trackbacks">-</td>
</tr>
</tbody>
+ <tfoot>
+ <tr>
+ <td class="post-num_comments">0</td>
+ <td class="post-num_trackbacks">0</td>
+ </tr>
+ </tfoot>
</table>
=== Caveat Emptor
See the API for more information on syntax, options, and examples. You should only