Class: TableData

Inherits:
ActionView::Base
  • Object
show all
Defined in:
lib/table_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(label_size) ⇒ TableData

Returns a new instance of TableData.



5
6
7
# File 'lib/table_data.rb', line 5

def initialize(label_size)
  @label_size = label_size
end

Instance Method Details

#row(label, data, colspan = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/table_data.rb', line 9

def row(label, data, colspan=false)
  data = data.to_s.html_safe
  label = label.to_s.html_safe

  unless @set_label_size && @label_size
    unless colspan
      result =  :tr do
        (:td, label, :class => "label", :width => @label_size) <<
        (:td, data)
      end
    else
      result =  :tr do
        (:td, (:span, label, :class => "label", :style => "display: block; float: left; width: #{@label_size}px;") << data, :colspan => 2, :width => @label_size)
      end
    end
    
    @set_label_size = true
  else
    unless colspan
      result =  :tr do
        (:td, label, :class => "label") <<
        (:td, data)
      end
    else
      result =  :tr do
        (:td, (:span, label, :class => "label", :style => "display: block; float: left; width: #{@label_size}px;") << data, :colspan => 2, :width => @label_size)
      end
    end
  end
  
  result
end

#section(name = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/table_data.rb', line 42

def section(name=nil)
  name = name.to_s.html_safe
  
  if name.present?
     :tr do
       :td, (:div, name, :class => "section"), :colspan => 2
    end
  else
     :tr do
       :td, tag(:hr, :class => "section"), :colspan => 2
    end
  end
end