ModelTableizer

Given a collection of objects where within the object instance variables are accessable, as method calls, produce an html table layout for the collection. Since this generates raw html you can use in any ruby web application server(Sinatra, Rails, Camping, etc...)

Example: users = [ User.new(:name => 'Some Name 1', :email => 'some email 1', :created_at => Time.now, :beta_request => '/shome_url_1'), User.new(:name => 'Some Name 2', :email => 'some email 2', :created_at => Time.now, :beta_request => ''), User.new(:name => 'Some Name 3', :email => 'some email 3', :created_at => Time.now, :beta_request => '/shome_url_3') ]

table users, :id => 'list_of_users' do column :name, :id => 'blah_id' column :email column :created_at column "CRM Status", :id => 'from_crm' do "#{user.beta_request}" if user.beta_request end end

Results in:

NameCreated AtCrm Status
Some Name 1some email 12012-04-06 15:37:49 -0700/shome_url_1
Some Name 2some email 22012-04-06 15:37:49 -0700
Some Name 3some email 32012-04-06 15:37:49 -0700/shome_url_3

Installation

Add this line to your application's Gemfile:

gem 'model_tableizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install model_tableizer

Usage

include ModelTableizer

If you are going to be using this with Rails, in your application controller add the above include line. Then in a controller method make a call such as:

@user_table = table users, :id => 'list_of_users' do
  column :name, :id => 'blah_id'
  column :email
  column :created_at
  column "CRM Status", :id => 'from_crm' do
    "<a href='#{user.beta_request}'>#{user.beta_request}</a>" if user.beta_request
  end
end

Then in your view you can access

<% raw(@user_table) %>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

GPLv3: http://www.gnu.org/licenses/gpl.html