Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add README

  • Loading branch information...
commit f879795d4eaf5f63d9184106904e4752d2d02af7 1 parent a533a6f
Joe Fiorini authored
Showing with 79 additions and 17 deletions.
  1. +0 −17 README.rdoc
  2. +79 −0 README.textile
View
17 README.rdoc
@@ -1,17 +0,0 @@
-= totally_tabular
-
-Description goes here.
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
-
-== Copyright
-
-Copyright (c) 2010 Joe Fiorini. See LICENSE for details.
View
79 README.textile
@@ -0,0 +1,79 @@
+h1. Totally Tabular!
+
+ Assuming I have 5 people with:
+
+ * first_name
+ * last_name
+ * registration_status
+
+ My pointy-haired boss wants to see a list of these people on our
+ administrative dashboard. Sure, I could write some ugly ERB like so:
+
+<pre>
+ <code>
+ <table class="people">
+ <thead>
+ <tr>
+ <th class="header">First Name</th>
+ <th>Last Name</th>
+ <th>Registration Status</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @people.each do |person| %>
+ <tr class="<%= person.registration_status %>">
+ <td>Michael Bluth</td>
+ <td>Bluth</td>
+ <td>
+ <% if person.registered? %>
+ <strong>Registered</strong>
+ <% else %>
+ <em>Unregistered</em>
+ <% end %>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ </code>
+</pre>
+
+ But why? I mean, we're using Ruby for Pete's sake! How about a cleaner way to do the same thing?
+
+<pre>
+ <code>
+ <%= person_table(people_presenter.people, :class => 'people') %>
+ </code>
+</pre>
+
+ 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.
+
+<pre>
+ <code>
+ 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
+ </code>
+</pre>
+
Please sign in to comment.
Something went wrong with that request. Please try again.