AwesomeTables
This rails gem is used to easily display, consistently styled tables. It is still very much a work in progress.
Example
In order to use an awesome_table, first you must register it in a helper. Two examples are below.
AwesomeTables::AwesomeTable::register :posts do |t|
t.set_caption “Posts” t.column :published_at, :display_published_at t.column :post, :partial => ‘awesome_tables/posts/body’ t.column :comment_count, :comment_counter, :with_image => ‘comment-grey-bubble.png’ end
AwesomeTables::AwesomeTable::register :users do |t| t.set_caption “Users” t.column :full_name t.column :login t.column :email t.column :state end
Now you can use them in your views
<%= awesome_table :users, @users %>
<%= awesome_table :posts, @posts %>
There are currently 3 different ways to declare a column.
-
t.column(:method) A plain td can be created by passing in an object attribute. The header will be a titlized version of the method name.
-
t.column(:header_text, :method) If you want the header text to be different than the method.
-
t.column(:header_text, :partial => ‘path/to/partial) If your td data is more complex than a method name, add a partial option.
Eventually, I want to be able to create columns that use view_helpers, but I haven’t spent enough time investigating how to get that working.
-
t.column(:header_text, link_to(obj.name, obj))
The :with_image option will use the image as the column header instead header text. That code and the way it is used needs some attention. Things have changed a little bit since I put that in there.
You’ll need to make sure that you create an awesome tables view folder. There is a base example table contained in lib/app/views/awesome_tables.
TODO
-
create a generator that creates awesome_tables view folder and copies a base table into it.
-
tests, tests, tests
-
allow use of helpers in column calls
-
figure out how to change the templates so that they don’t have column loops inside of the object loop
-
add more and better options support. Currently there is only a :class (and :with_image) option for columns and the way the :class option is implemented looks nasty.
-
have awesome_tables infer objects the way will_paginate does. That was working, I changed it for some reason to work around something that I can’t currently remember.
-
create different formatters so awesome_tables can be used to output tables in formats other than html tables.
Copyright © 2010 Dan Engle, released under the MIT license