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 # # # #
# #{N::TableBuilder.build(users, header)} #
# # or: # #
# #{@out.build_table(users, header)} #
#-- # 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 = '' for h in c[:headers] buf << %|#{h}| end buf << "" for row in c[:values] buf << "" for v in row buf << %|#{v}| end buf << "" end buf << "" 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 # * George Moschovitis