Class: BootstrapTableHelper::Row

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/bootstrap_table_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}, &block) ⇒ Row

Returns a new instance of Row.



10
11
12
13
14
15
# File 'app/helpers/bootstrap_table_helper.rb', line 10

def initialize(template, options={}, &block)
  self.template = template
  self.options = options
  self.columns = []
  block.call(self)
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



8
9
10
# File 'app/helpers/bootstrap_table_helper.rb', line 8

def columns
  @columns
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'app/helpers/bootstrap_table_helper.rb', line 8

def options
  @options
end

#templateObject

Returns the value of attribute template.



8
9
10
# File 'app/helpers/bootstrap_table_helper.rb', line 8

def template
  @template
end

Instance Method Details

#column(width, options = {}, &block) ⇒ Object



17
18
19
20
21
22
# File 'app/helpers/bootstrap_table_helper.rb', line 17

def column(width, options={}, &block)
  width, options = nil, width if width.is_a?(Hash)
  options[:class] ||= ''
  options[:class] << "span#{width}" if width && width.to_i < 12 && width.to_i > 0
  columns << [options, block]
end

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/bootstrap_table_helper.rb', line 24

def to_s
  template.(:tr, nil, options) do
    tr_content = []
    columns.each do |column|
      column_options = column.first
      column_options[:style] ||= ''
      column_options[:style] << "text-align: #{column_options[:align]||'left'};"
      tr_content << template.(:td, nil, column_options.dup.delete_if { |k, v| k.to_s == 'align' }) do
        template.capture(&column.second) if column.second
      end
    end

    tr_content.join.html_safe
  end
end