Class: BootstrapTabHelper::TabBuilder
- Inherits:
-
Object
- Object
- BootstrapTabHelper::TabBuilder
- Defined in:
- app/helpers/bootstrap_tab_helper.rb
Instance Attribute Summary collapse
-
#default_index ⇒ Object
Returns the value of attribute default_index.
-
#options ⇒ Object
Returns the value of attribute options.
-
#tabs ⇒ Object
Returns the value of attribute tabs.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(index, template, options = {}) ⇒ TabBuilder
constructor
A new instance of TabBuilder.
-
#tab(label, options = {}, &proc) ⇒ Object
tab label and content of tabs.
- #to_s ⇒ Object
Constructor Details
#initialize(index, template, options = {}) ⇒ TabBuilder
Returns a new instance of TabBuilder.
10 11 12 13 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 10 def initialize(index, template, ={}) @default_index, @options, @template = index, , template @tabs = {} end |
Instance Attribute Details
#default_index ⇒ Object
Returns the value of attribute default_index.
8 9 10 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 8 def default_index @default_index end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 8 def @options end |
#tabs ⇒ Object
Returns the value of attribute tabs.
8 9 10 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 8 def tabs @tabs end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 8 def template @template end |
Instance Method Details
#tab(label, options = {}, &proc) ⇒ 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
24 25 26 27 28 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 24 def tab(label, ={}, &proc) = {disabled: false, clickable: true} = .delete(:pane_options) || {} @tabs[label] = [.reverse_merge!(), , proc] end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/bootstrap_tab_helper.rb', line 30 def to_s style = @options.delete(:style) inline = @options.delete(:inline) position = @options.delete(:position) #align = @options.delete(:align) stacked = @options.delete(:stacked) @options[:class] ||= '' @options[:class] << ' nav-stacked' if stacked #@options[:class] << " pull-#{align}" if align @options[:class] << ' nav nav-tabs' if style == 'tab' @options[:class] << ' nav nav-pills' if style == 'pill' = {style: "display: #{inline ? 'inline-block' : 'block'};", class: " tabbable tabs-#{position}"} = @options.delete(:content_options) || {} [:class] ||= '' [:class] << ' tab-content' @template.div() do tab_content = '' tab_content << @template.list(@options) do |li| @tabs.keys.each do |k| render_label(li, style, k, @tabs.keys.index(k) == @default_index.to_i, "#{@options[:id]}-tab-#{@tabs.keys.index(k)}", @tabs[k][0]) end end tab_content << @template.div() do tab_panes = '' @tabs.values.each do |v| tab_panes << render_content(@tabs.values.index(v) == @default_index.to_i, "#{@options[:id]}-tab-#{@tabs.values.index(v)}", v[1], &v[2]) end tab_panes.html_safe end tab_content.html_safe end end |