Sha256: c0c24015efec06a736bca92413b964d4ef8618378c0f1c45953d1df25c934c6e
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
# * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. # $Id: table.rb 1 2005-04-11 11:04:30Z gmosx $ module Nitro # The TableBuilder is a helper class that automates the creation # of tables from collections of objects. The resulting html # can be styled using css. # # === Example # # <?r # users = User.all.map { |u| [u.name, u.first_name, u.last_name, u.email] } # header = ['Username', 'First name', 'Last name', 'Email'] # ?> # # <div class="custom-table-class"> # #{N::TableBuilder.build(users, header)} # </div> # # or: # # <div class="custom-table-class"> # #{@out.build_table(users, header)} # </div> #-- # TODO: sorting, thead/tbody/legend etc, verbose... #++ module TableBuilderMixin # [+options+] # A hash of options. # # :id = id of the component. # :headers = an array of the header values # :values = an array of arrays. def build_table(options) c = options buf = '<table' buf << %| id="#{c[:id]}"| if c[:id] buf << '><tr>' for h in c[:headers] buf << %|<th>#{h}</th>| end buf << "</tr>" for row in c[:values] buf << "<tr>" for v in row buf << %|<td>#{v}</td>| end buf << "</tr>" end buf << "</table>" return buf end end # Abstract class for the TableBuilderMixin. class TableBuilder include TableBuilderMixin class << self def build(options) TableBuilder.new.build_table(options) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.16.0 | lib/nitro/builders/table.rb |
nitro-0.17.0 | lib/nitro/builders/table.rb |