Class: Bootstrap::TabHelper::Tabs
- Inherits:
-
Object
- Object
- Bootstrap::TabHelper::Tabs
- Defined in:
- app/helpers/bootstrap/tab_helper.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#content_options ⇒ Object
readonly
Returns the value of attribute content_options.
-
#default_index ⇒ Object
readonly
Returns the value of attribute default_index.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#inline ⇒ Object
readonly
Returns the value of attribute inline.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#stacked ⇒ Object
readonly
Returns the value of attribute stacked.
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(template, index: 0, inline: false, stacked: false, id: 'tabs', type: 'tabs', position: 'top', align: 'left', content_options: {}, **options) ⇒ Tabs
constructor
A new instance of Tabs.
-
#tab(label, disabled: false, pane_options: {}, **options, &block) ⇒ Object
tab label and content of tabs.
- #to_s ⇒ Object
Constructor Details
#initialize(template, index: 0, inline: false, stacked: false, id: 'tabs', type: 'tabs', position: 'top', align: 'left', content_options: {}, **options) ⇒ Tabs
Returns a new instance of Tabs.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 7 def initialize(template, index: 0, inline: false, stacked: false, id: 'tabs', type: 'tabs', position: 'top', align: 'left', content_options: {}, **) @default_index = index @inline = inline @stacked = stacked @id = id @type = type @position = position @align = align @content_options = @options = @template = template @tabs = {} end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def align @align end |
#content_options ⇒ Object (readonly)
Returns the value of attribute content_options.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def @content_options end |
#default_index ⇒ Object (readonly)
Returns the value of attribute default_index.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def default_index @default_index end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def id @id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def index @index end |
#inline ⇒ Object (readonly)
Returns the value of attribute inline.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def inline @inline end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def @options end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def position @position end |
#stacked ⇒ Object (readonly)
Returns the value of attribute stacked.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def stacked @stacked end |
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def tabs @tabs end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def template @template end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 4 def type @type end |
Instance Method Details
#tab(label, disabled: false, pane_options: {}, **options, &block) ⇒ Object
tab label and content of tabs
label - label of tab options -
disabled - true, false default: false
clickable - true, false default: true
other options that can be accpted by li
pane_options -
every option that can be accepted by div
39 40 41 42 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 39 def tab(label, disabled: false, pane_options: {}, **, &block) tabs[label] = { disabled: disabled, pane_options: , options: , content: block } end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/bootstrap/tab_helper.rb', line 44 def to_s = { style: "display: #{inline ? 'inline-block' : 'block'};", class: " tabbable tabs-#{position}" } template.div() do tab_content = '' tab_content << template.nav(.merge!(type: type, stacked: stacked)) do |item| tabs.keys.each_with_index do |k, i| = (i == default_index.to_i) ? { class: "active" } : {} item.add(render_label(type, k, "#{id}-tab-#{i}", tabs[k]), ) end end tab_content << template.div(template.merge_predef_class('tab-content', )) do tab_panes = '' tabs.values.each_with_index do |v, i| tab_panes << render_content(i == default_index.to_i, "#{id}-tab-#{i}", v) end tab_panes.html_safe end tab_content.html_safe end end |