Class: Bootstrap::TabHelper::Tabs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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: {},
  **options)
  @default_index = index
  @inline = inline
  @stacked = stacked
  @id = id
  @type = type
  @position = position
  @align = align
  @content_options = content_options
  @options = options
  @template = template
  @tabs = {}
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def align
  @align
end

#content_optionsObject (readonly)

Returns the value of attribute content_options.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def content_options
  @content_options
end

#default_indexObject (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

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def id
  @id
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def index
  @index
end

#inlineObject (readonly)

Returns the value of attribute inline.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def inline
  @inline
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def options
  @options
end

#positionObject (readonly)

Returns the value of attribute position.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def position
  @position
end

#stackedObject (readonly)

Returns the value of attribute stacked.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def stacked
  @stacked
end

#tabsObject (readonly)

Returns the value of attribute tabs.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def tabs
  @tabs
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'app/helpers/bootstrap/tab_helper.rb', line 4

def template
  @template
end

#typeObject (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: {}, **options, &block)
  tabs[label] = { disabled: disabled, pane_options: pane_options,
    options: options, content: block }
end

#to_sObject



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
  tab_wrapper_options = { style: "display: #{inline ? 'inline-block' : 'block'};",
    class: " tabbable tabs-#{position}" }

  template.div(tab_wrapper_options) do
    tab_content = ''
    tab_content << template.nav(options.merge!(type: type, stacked: stacked)) do |item|
      tabs.keys.each_with_index do |k, i|
        li_options = (i == default_index.to_i) ? { class: "active" } : {}
        item.add(render_label(type, k, "#{id}-tab-#{i}", tabs[k]), li_options)
      end
    end

    tab_content << template.div(template.merge_predef_class('tab-content', content_options)) 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