Class: BootstrapComponentsHelpers::TabsHelper::TabsBuilder
- Inherits:
-
Object
- Object
- BootstrapComponentsHelpers::TabsHelper::TabsBuilder
- Includes:
- ActionView::Helpers::OutputSafetyHelper
- Defined in:
- lib/bootstrap-components-helpers/tabs_helper.rb
Instance Attribute Summary collapse
-
#pane_contents ⇒ Object
readonly
Returns the value of attribute pane_contents.
-
#pane_handles ⇒ Object
readonly
Returns the value of attribute pane_handles.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(parent) ⇒ TabsBuilder
constructor
A new instance of TabsBuilder.
- #pane(title, options = {}, &block) ⇒ Object
- #pane_contents_html ⇒ Object
- #pane_handles_html ⇒ Object
Constructor Details
#initialize(parent) ⇒ TabsBuilder
Returns a new instance of TabsBuilder.
22 23 24 25 26 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 22 def initialize parent @parent = parent @pane_handles = [] @pane_contents = [] end |
Instance Attribute Details
#pane_contents ⇒ Object (readonly)
Returns the value of attribute pane_contents.
19 20 21 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 19 def pane_contents @pane_contents end |
#pane_handles ⇒ Object (readonly)
Returns the value of attribute pane_handles.
19 20 21 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 19 def pane_handles @pane_handles end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
19 20 21 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 19 def parent @parent end |
Instance Method Details
#pane(title, options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 28 def pane title, = {}, &block css_class = [:active] ? 'active' : '' tab_id = [:id] || default_tab_id(title) link = content_tag(:a, 'data-toggle': 'tab', href: "##{tab_id}") do if [:icon] title = raw(content_tag(:i, '', class: [:icon].to_s) + ' ' + title) end title end content = capture(&block) if content.present? @pane_handles << [link, css_class] @pane_contents << [[css_class, [:class]], title, tab_id, content] end nil end |
#pane_contents_html ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 53 def pane_contents_html return if pane_contents.empty? pane_contents.first[0] << 'active' unless pane_contents.detect {|pc| pc[0].include? 'active'} pane_contents.map do |css_class, title, tab_id, content| css_class << 'in' if css_class.include?('active') && css_class.include?('fade') css_class = css_class.join(' ').strip content_tag :div, content, class: "tab-pane #{css_class}", id: tab_id.to_s end.join("\n").html_safe end |
#pane_handles_html ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bootstrap-components-helpers/tabs_helper.rb', line 45 def pane_handles_html return if pane_handles.empty? pane_handles.first[1] = 'active' unless pane_handles.detect {|ph| ph[1] == 'active'} pane_handles.map do |link, css_class| content_tag(:li, link, class: css_class) end.join("\n").html_safe end |