Class: Bootstrap3Helper::Accordion
- Defined in:
- lib/bootstrap3_helper/accordion.rb
Overview
Used to generate Bootstrap Accordion objects.
Instance Method Summary collapse
-
#body(tag_or_options = nil, opts = {}, &block) ⇒ Object
Creates the body element for the accordion.
-
#footer(tag_or_options = nil, opts = {}, &block) ⇒ String
Creates the footer element for the accordion.
-
#header(tag_or_options = nil, opts = {}, &block) ⇒ String
Creates the header element for the accordion.
-
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Accordion
constructor
Initlize a new accordion object.
-
#title(tag_or_options = nil, opts = {}, &block) ⇒ String
Builds a title component for the accordion header.
-
#to_s ⇒ String
The to string method here is what is responsible for rendering out the accordion element.
Methods inherited from Component
#concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #uuid
Constructor Details
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Accordion
Initlize a new accordion object. If this part of a parent element, i.e AccordionGroup, we need to keep track of the parent element id, so we can pass it down to the other components.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bootstrap3_helper/accordion.rb', line 20 def initialize(template, = nil, opts = {}, &block) super(template) @context, args = (, opts) @parent_id = args.fetch(:parent_id, nil) @id = args.fetch(:id, nil) @class = args.fetch(:class, '') @collapse_id = args.fetch(:collapse_id, uuid) @expanded = args.fetch(:expanded, false) @content = block || proc { '' } @panel = Panel.new(@template, , opts) end |
Instance Method Details
#body(tag_or_options = nil, opts = {}, &block) ⇒ Object
NilClass :to_s returns an empty String
Creates the body element for the accordion.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bootstrap3_helper/accordion.rb', line 87 def body( = nil, opts = {}, &block) tag, args = (, opts) klass = 'panel-collapse collapse ' klass += ' in' if @expanded content_tag( :div, id: @collapse_id, role: 'tabpanel', class: klass, aria: { labelledby: "##{@collapse_id}" } ) do @panel.body(tag, args.merge!(config_for: :accordions), &block) end end |
#footer(tag_or_options = nil, opts = {}, &block) ⇒ String
Creates the footer element for the accordion
112 113 114 115 |
# File 'lib/bootstrap3_helper/accordion.rb', line 112 def ( = nil, opts = {}, &block) tag, args = (, opts) @panel.(tag, args.merge!(config_for: :accordions), &block) end |
#header(tag_or_options = nil, opts = {}, &block) ⇒ String
Creates the header element for the accordion
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bootstrap3_helper/accordion.rb', line 43 def header( = nil, opts = {}, &block) tag, args = (, opts) data = {} data[:toggle] = 'collapse' data[:parent] = "##{@parent_id}" if @parent_id.present? data[:target] = "##{@collapse_id}" @panel.header(tag, args.merge!(config_for: :accordions)) do content_tag( :span, role: 'button', data: data, aria: { expanded: @expanded, controls: "##{@collapse_id}" }, &block ) end end |
#title(tag_or_options = nil, opts = {}, &block) ⇒ String
Builds a title component for the accordion header.
72 73 74 75 |
# File 'lib/bootstrap3_helper/accordion.rb', line 72 def title( = nil, opts = {}, &block) tag, args = (, opts) @panel.title(tag, args.merge!(config_for: :accordions), &block) end |
#to_s ⇒ String
The to string method here is what is responsible for rendering out the accordion element. As long as the main method is rendered out in the helper, you will get the entire accordion.
123 124 125 126 127 |
# File 'lib/bootstrap3_helper/accordion.rb', line 123 def to_s content_tag :div, id: @id, class: container_classes do @content.call(self) end end |