Class: Bootstrap5Helper::Accordion

Inherits:
Component
  • Object
show all
Defined in:
lib/bootstrap5_helper/accordion.rb,
lib/bootstrap5_helper/accordion/item.rb

Overview

Builds a Accordion component.

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid

Constructor Details

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

Class constructor

Parameters:

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

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)
  • :always_open (Boolean)
  • :flush (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/bootstrap5_helper/accordion.rb', line 16

def initialize(template, opts = {}, &block)
  super(template)

  @id          = opts.fetch(:id,          uuid)
  @class       = opts.fetch(:class,       '')
  @data        = opts.fetch(:data,        {})
  @always_open = opts.fetch(:always_open, false)
  @flush       = opts.fetch(:flush,       false)
  @content     = block || proc { '' }
end

Instance Method Details

#item(opts = {}, &block) ⇒ Accodion::Item

Used to generate a Accordion::Item component.

Returns:

  • (Accodion::Item)


31
32
33
# File 'lib/bootstrap5_helper/accordion.rb', line 31

def item(opts = {}, &block)
  Accordion::Item.new(self, (@always_open ? nil : @id), opts, &block)
end

#to_sString

String representation of the object.

Returns:

  • (String)


39
40
41
42
43
44
45
46
47
48
# File 'lib/bootstrap5_helper/accordion.rb', line 39

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