Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joefiorini/totally_tabular
https://github.com/joefiorini/totally_tabular
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/joefiorini/totally_tabular
- Owner: joefiorini
- License: mit
- Created: 2010-01-16T23:06:13.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2010-02-06T23:50:27.000Z (almost 15 years ago)
- Last Synced: 2024-04-14T09:06:44.324Z (9 months ago)
- Language: Ruby
- Size: 95.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
h1. Totally Tabular!
Assuming I have 5 people with:
* first_name
* last_name
* registration_statusMy pointy-haired boss wants to see a list of these people on our
administrative dashboard. Sure, I could write some ugly ERB like so:
First Name
Last Name
Registration Status
<% @people.each do |person| %>
Michael Bluth
Bluth
<% if person.registered? %>
Registered
<% else %>
Unregistered
<% end %>
<% end %>
But why? I mean, we're using Ruby for Pete's sake! How about a cleaner way to do the same thing?
<%= person_table(people_presenter.people, :class => 'people') %>
Okay, so that's just a custom Rails helper method. Nothing special. But let's look at the definition of the helper method! That's where the special sauce is.
def person_table(people, attributes={})
TableView.new(@people, :class => 'people') do
define_column("First Name") do |person|
header_attributes!(:class => 'header')
row_attributes!(:class => person.registration_status)
template! do
person.first_name
end
end
define_column("Last Name") do |person|
template! do
person.last_name
end
end
define_column("Registration Status") do |person|
template! do
if person.registered?
content_tag(:strong, "Registered")
else
content_tag(:em, "Unregistered")
end
end
end
end
end