Class: Bootstrap4Helper::AccordionGroup
- Defined in:
- lib/bootstrap4_helper/accordion_group.rb
Overview
Used to build groups of Accordions, that are all synced with each other.
Instance Method Summary collapse
-
#accordion(*args, &block) ⇒ Accordion
Used to build a ‘Accordion` for the `AccordionGroup`.
-
#initialize(template, opts = {}, &block) ⇒ AccordionGroup
constructor
Class constructor.
-
#to_s ⇒ String
Used to get the HTML markup of the ‘AccordionGroup`.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ AccordionGroup
Class constructor
14 15 16 17 18 19 20 21 |
# File 'lib/bootstrap4_helper/accordion_group.rb', line 14 def initialize(template, opts = {}, &block) super(template) @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#accordion(*args, &block) ⇒ Accordion
Used to build a ‘Accordion` for the `AccordionGroup`.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bootstrap4_helper/accordion_group.rb', line 28 def accordion(*args, &block) opts = *args if opts.any? { |opt| opt.is_a?(Hash) } opts.collect! { |opt| opt[:parent] = @id if opt.is_a?(Hash) } else opts << { parent: @id } end Accordion.new(self, *opts, &block) end |
#to_s ⇒ String
Used to get the HTML markup of the ‘AccordionGroup`
44 45 46 47 48 |
# File 'lib/bootstrap4_helper/accordion_group.rb', line 44 def to_s content_tag :div, id: @id, class: "accordion #{@class}", data: @data do @content.call(self) end end |