Class: TotallyTabular::TableView

Inherits:
Object
  • Object
show all
Defined in:
lib/totally_tabular/table_view.rb

Instance Method Summary collapse

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, options={}, &block)
  @collection = collection
  @calling_object = options.delete(:self)
  @options = options
  @column_definition = block
  @helper = HtmlHelper.new
end

Instance Method Details

#optionsObject



32
33
34
# File 'lib/totally_tabular/table_view.rb', line 32

def options
  @options
end

#renderObject



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.(:tbody, rows.join)
  thead = @helper.(:thead, headers)
  tfoot = @helper.(:tfoot)
  @helper.(:table, [thead, tbody, tfoot], options)
end