class Bootstrap4Helper::AccordionGroup

Used to build groups of Accordions, that are all synced with each other.

Public Class Methods

new(template, opts = {}, &block) click to toggle source

Class constructor

@param [ActionView] template @param [Hash] opts @option opts [String] :id @option opts [String] :class @option opts [Hash] :data

Calls superclass method
# 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

Public Instance Methods

accordion(*args, &block) click to toggle source

Used to build a `Accordion` for the `AccordionGroup`.

@param [Mixed] args @return [Accordion]

# 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() click to toggle source

Used to get the HTML markup of the `AccordionGroup`

@return [String]

# 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