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
20
21
# File 'lib/tablette/table.rb', line 14

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

Dynamic Method Handling

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

Instance Method Details



29
30
31
32
33
# File 'lib/tablette/table.rb', line 29

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

#header(&block) ⇒ Object



23
24
25
26
27
# File 'lib/tablette/table.rb', line 23

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

#to_html(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tablette/table.rb', line 35

def to_html(*args)
  columns = 0

  all_sections = [ self.header!, build_autoheader(args), 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

  @sections_to_render = all_sections
  begin
    @renderer.to_html(super)
  ensure
    @sections_to_render = nil
  end
end