# Tablinate ## Author(s) * [Isabelle Carter](http://github.com/ibnc) * [Kevin Collette](http://github.com/collettiquette) ## Note This project is dead. It was something I made years ago with friends when we were still not great programmers. It was never a good idea, but it was fun to write none the less. This is still up because I see no reason to take it down, and I occasionally use this repo as a test repo on other projects. ## Description Tablinate is a ruby gem that takes arrays of hashes, ActiveRecord::Relation objects, or a JSON array of hashes, and converts them into html tables. It is intended for use in small projects or applications whose schemas are closely related to standard table formats. ## Install gem install tablinate ## Sample Sinatra Code: ### 1) app.rb require 'sinatra' require 'tablinate' get '/' do @employees = [ { :id => '1', :first_name => "Matt", :last_name => "Smith", :title => "Time Lord" }, { :id => '2', :first_name => "Jack", :last_name => "Harkness", :title => "Time Agent" }, { :id => '3', :first_name => "Tom", :last_name => "Baker", :title => "Time Lord" }, { :id => '4', :first_name => "David", :last_name => "Tennant", :title => "Time Lord" }, { :id => '5', :first_name => "Christopher", :last_name => "Eccleston", :title => "Time Lord" } ] haml :index end ### 2) views/index.haml %body = @employees.tablinate() ### 3) view-source:http://localhost:4567/
id first_name last_name title
1 Matt Smith Time Lord
2 Jack Harkness Time Agent
3 Tom Baker Time Lord
4 David Tennant Time Lord
5 Christopher Eccleston Time Lord
## Options Because it uses normal html markup, tablinated tables are easily styled using CSS, Sass, etc. That being said, tablinate is configurable via an options hash. The hash can style the table or add classes to it. For example: ### views/index.haml %body =@employees.tablinate( { :table => { :border => 1, :class => 'fluid' }, :tbody => { :class => 'foo' } } ) ### view-source:http://localhost:4567/ ... ... ### Further notes on options Options are highly expandable, and support many useful notations. For example: @table_params = { :table => { :class => "table" }, :tbody => { :tr => { :class => [ 'class1', 'class2', 'class3' ], :id => 'meow' }, :td => { :class => 'row', :id => [1,2,3] } } } @table = [ { :column1 => 'value1', :column2 => 'value2', :column3 => 'value3' }, { :column1 => 'value1', :column2 => 'value2', :column3 => 'value3' }, { :column1 => 'value1', :column2 => 'value2', :column3 => 'value3' }, { :column1 => 'value1', :column2 => 'value2', :column3 => 'value3' } ] @table.tablinate(@table_params)
id first_name last_name title
1 Matt
column1 column2 column3
value1 value2 value3
value1 value2 value3
value1 value2 value3
value1 value2 value3
### Haml note When using haml, you may need to unescape html tags by: %body != [ { ... }, ... ].tablinate(...)