/tablebuilder

Table Builder is a simple and flexible table generator for your Rails 3 views.

Primary LanguageRubyMIT LicenseMIT

Table Builder

Table Builder is a simple and flexible table generator for your Rails 3 views. It creates a table for a collection of objects where every objects maps to one row of your table. It is designed for clean and readable template code but attempts to be very flexible.

This project is in a very early development stage, so do not expect everything to work yet, but your feedback is appreciated.

Dependencies

This gem requires Rails 3 and should work with Ruby 1.8.7 and 1.9.2.

Install

Add the following line to your Gemfile:

gem "tablebuilder", :git => "https://github.com/mbreit/tablebuilder"

Usage

Use the table_for helper in your views:

<%= table_for @users, :class => "users_table" do |t| %>
  <% t.column :username %>
  <% t.column :email %>
  <% t.column :actions, :class => "actions" do |user| %>
    <%= link_to "View", user %>
    <%= link_to "Edit", edit_user_path(user) %>
  <% end %>
<% end %>

Or, if you prefer HAML:

= table_for @users, :class => "users_table" do |t|
  - t.column :username
  - t.column :email
  - t.column :actions, :class => "actions" do |user|
    = link_to "View", user
    = link_to "Edit", edit_user_path(user)

This is equivalent to the following ERB code:

<table class="users_table">
  <thead>
    <th><%= t('.username') %></th>
    <th><%= t('.email') %></th>
    <th><%= t('.actions') %></th>
  </thead>
  <tbody>
    <% @users.each do |user| %>
      <tr class="<%= cycle('odd', 'even') %>">
        <td>
          <%= user.username %>
        </td>
        <td>
          <%= user.email %>
        </td>
        <td class="actions">
          <%= link_to "View", user %>
          <%= link_to "Edit", edit_user_path(user) %>
        </td>
      </td>
    <% end %>
  </tbody>
</table>

Feedback

If you have feedback like questions, bugs or feature requests, you can send me a message on Github, send me a mail or create an issue at Github.

Contributing

If you want to contribute some changes to the tablebuilder gem, don’t hesitate to contact me. You can fork the project on Github and send me a pull request or send me patches via email.

Licence

Copyright © 2011 Moritz Breit. See LICENSE.txt for further details.