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(options = {}, &block) ⇒ Object



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

def column(options={}, &block)
  columns << [options, block]
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/bootstrap_table_helper.rb', line 21

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)
      end
    end

    tr_content.join.html_safe
  end
end