Class: Bootstrap::TableHelper::Row
- Inherits:
-
Object
- Object
- Bootstrap::TableHelper::Row
- Defined in:
- app/helpers/bootstrap/table_helper.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #column(width: nil, align: 'left', text: nil, tag: :td, **options, &block) ⇒ Object
- #header(tag: :th, **options, &block) ⇒ Object
-
#initialize(template, options = {}) ⇒ Row
constructor
A new instance of Row.
- #to_s ⇒ Object
Constructor Details
#initialize(template, options = {}) ⇒ Row
Returns a new instance of Row.
7 8 9 10 11 |
# File 'app/helpers/bootstrap/table_helper.rb', line 7 def initialize(template, = {}) @template = template @options = @columns = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'app/helpers/bootstrap/table_helper.rb', line 5 def columns @columns end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'app/helpers/bootstrap/table_helper.rb', line 5 def @options end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'app/helpers/bootstrap/table_helper.rb', line 5 def template @template end |
Instance Method Details
#column(width: nil, align: 'left', text: nil, tag: :td, **options, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/bootstrap/table_helper.rb', line 13 def column(width: nil, align: 'left', text: nil, tag: :td, **, &block) if width && width.to_i <= 12 && width.to_i > 0 template.merge_predef_class("span#{width.to_i}", ) end columns << { options: , align: align, text: text, tag: tag, content: block } end |
#header(tag: :th, **options, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/bootstrap/table_helper.rb', line 27 def header(tag: :th, **, &block) if block_given? column(.merge!(tag: tag)) do template.capture(&block) end else column(.merge!(tag: tag)) end end |
#to_s ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/bootstrap/table_helper.rb', line 37 def to_s template.content_tag(:tr, nil, ) do tr_content = '' columns.each do |c| = c[:options] [:style] ||= '' [:style] << "text-align: #{c[:align]};" tr_content << template.content_tag(c[:tag], nil, ) do if c[:content] template.capture(&c[:content]) else c[:text] end end end tr_content.html_safe end end |