Class: Tablette::Table

Inherits:
Element show all
Defined in:
lib/tablette/table.rb

Instance Attribute Summary

Attributes inherited from Element

#helper, #renderer

Instance Method Summary collapse

Methods inherited from Element

#element_to_html, #method_missing, #respond_to_missing?

Constructor Details

#initialize(*args, &block) ⇒ Table

Returns a new instance of Table.



14
15
16
17
18
19
# File 'lib/tablette/table.rb', line 14

def initialize(*args, &block)
  @renderer = HTMLRenderer.new
  @helper = nil
  
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tablette::Element

Instance Method Details



27
28
29
30
31
# File 'lib/tablette/table.rb', line 27

def footer(&block)
  footer! do
    column(html_options: { colspan: 'auto'}, &block)
  end
end

#header(&block) ⇒ Object



21
22
23
24
25
# File 'lib/tablette/table.rb', line 21

def header(&block)
  header! do
    column(html_options: { colspan: 'auto'}, &block)
  end
end

#to_html(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tablette/table.rb', line 33

def to_html(*args)
  columns = 0

  all_sections = [ self.header!, self.body, self.footer! ].flatten
  all_sections.each do |section|
    section_columns = section.columns_for_section args
    columns = section_columns if section_columns > columns
  end

  all_sections.each do |section|
    section.update_auto_colspan! columns, args
  end

  @renderer.to_html(super)
end