Class: Bootstrap4Helper::AccordionGroup

Inherits:
Component
  • Object
show all
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

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #uuid

Constructor Details

#initialize(template, opts = {}, &block) ⇒ AccordionGroup

Class constructor

Parameters:

  • template (ActionView)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)


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`.

Parameters:

  • args (Mixed)

Returns:



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_sString

Used to get the HTML markup of the ‘AccordionGroup`

Returns:

  • (String)


44
45
46
47
48
# File 'lib/bootstrap4_helper/accordion_group.rb', line 44

def to_s
   :div, id: @id, class: "accordion #{@class}", data: @data do
    @content.call(self)
  end
end