Class: Bootstrap3Helper::Accordion
- Defined in:
- lib/bootstrap3_helper/accordion.rb
Overview
Used to generate Bootstrap Accordion objects.
Instance Method Summary collapse
-
#body(args = {}, &block) ⇒ Object
Creates the body element for the accordion.
-
#footer(args = {}, &block) ⇒ Object
Creates the footer element for the accordion.
-
#header(args = {}, &block) ⇒ Object
Creates the header element for the accordion.
-
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Accordion
constructor
Initlize a new accordion object.
-
#to_s ⇒ String
The to string method here is what is responsible for rendering out the accordion element.
Methods inherited from Component
#concat, #content_tag, #parse_arguments, #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.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bootstrap3_helper/accordion.rb', line 31 def initialize(template, = nil, opts = {}, &block) super(template) @context, args = parse_arguments(, 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(args = {}, &block) ⇒ Object
NilClass :to_s returns an empty String
Creates the body element for the accordion.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bootstrap3_helper/accordion.rb', line 86 def body(args = {}, &block) 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(args, &block) end end |
#footer(args = {}, &block) ⇒ Object
Creates the footer element for the accordion
110 111 112 |
# File 'lib/bootstrap3_helper/accordion.rb', line 110 def (args = {}, &block) @panel.(args, &block) end |
#header(args = {}, &block) ⇒ Object
NilClass :to_s returns an empty String
Creates the header element for the accordion
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bootstrap3_helper/accordion.rb', line 56 def header(args = {}, &block) data = args.fetch(:data, {}) data[:toggle] = 'collapse' data[:parent] = "##{@parent_id}" if @parent_id.present? @panel.header(args) do content_tag( :a, href: "##{@collapse_id}", role: 'button', data: data, aria: { expanded: @expanded, controls: "##{@collapse_id}" }, &block ) end 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.
120 121 122 123 124 |
# File 'lib/bootstrap3_helper/accordion.rb', line 120 def to_s content = content_tag :div, id: @id, class: container_classes do @content.call(self) end end |