Class: TotallyTabular::TableView
- Defined in:
- lib/totally_tabular/table_view.rb
Instance Method Summary collapse
-
#initialize(collection, options = {}, &block) ⇒ TableView
constructor
A new instance of TableView.
- #options ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(collection, options = {}, &block) ⇒ TableView
Returns a new instance of TableView.
9 10 11 12 13 14 15 |
# File 'lib/totally_tabular/table_view.rb', line 9 def initialize(collection, ={}, &block) @collection = collection @calling_object = .delete(:self) @options = @column_definition = block @helper = HtmlHelper.new end |
Instance Method Details
#options ⇒ Object
32 33 34 |
# File 'lib/totally_tabular/table_view.rb', line 32 def @options end |
#render ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/totally_tabular/table_view.rb', line 17 def render table = Table.new table.instance_eval(&@column_definition) rows = build_rows(@collection, table.columns) headers = if @collection.empty? "" else build_headers(table.columns) end tbody = @helper.content_tag(:tbody, rows.join) thead = @helper.content_tag(:thead, headers) tfoot = @helper.content_tag(:tfoot) @helper.content_tag(:table, [thead, tbody, tfoot], ) end |