| Path: | lib/tidy_table.rb |
| Last Update: | Tue Jul 10 09:52:24 PDT 2007 |
This is yet another library to convert an ActiveRecord array (or any struct) to an HTML table.
You get a table with a bunch of CSS classes automatically applied (or customize it with your own classes and ids). For example, first_row (is also a th tag), first_column, last_column, even & odd (for rows).
Other tags like thead and tbody may be added in the future.
Simple example with an ActiveRecord object:
<%= TidyTable.new(@records).to_html(%w(title description created_at)) %>
You also format the row values with a block:
<%= TidyTable.new(@records, :table_class => "revenue_report").to_html(%w(resource visits min max)) do |row|
[
row.resource,
number_with_delimiter(row.visit_count),
row.min,
row.max
]
end %>
Or in HAML:
= TidyTable.new(@records, :table_class => "revenue_report").to_html(%w(resource visits min max)) do |row|
- [ row.resource, number_with_delimiter(row.visit_count), row.min, row.max ]