Class: Bootstrap3Helper::AccordionGroup

Inherits:
Component
  • Object
show all
Defined in:
lib/bootstrap3_helper/accordion_group.rb

Overview

This class is used to general groups of accordions.

Instance Method Summary collapse

Methods inherited from Component

#concat, #content_tag, #parse_arguments, #uuid

Constructor Details

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

Used to initialize the main object. This objects sole purpose is to generate a wrapper element with a distinct id and pass that id down to all the child elements.

Parameters:

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

Options Hash (opts):

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


39
40
41
42
43
44
45
46
# File 'lib/bootstrap3_helper/accordion_group.rb', line 39

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(context_or_options = nil, opts = {}) {|accordion| ... } ⇒ Object

This method is the main method for generating individual accordions. This is where you would pass in the html attributes.

Parameters:

  • - (NilClass|String|Symbol|Hash)

    Bootstrap class context, or options hash.

  • opts (Hash) (defaults to: {})
  • args (Hash)

    a customizable set of options

Yield Parameters:



57
58
59
60
61
62
63
64
65
# File 'lib/bootstrap3_helper/accordion_group.rb', line 57

def accordion(context_or_options = nil, opts = {}, &block)
  if context_or_options.is_a?(Hash)
    context_or_options[:parent_id] = @id
  else
    opts[:parent_id] = @id
  end

  Accordion.new(@template, context_or_options, opts, &block)
end

#to_sString

The to string method here is what is responsible for rendering out the entire accordion. As long as the main method is rendered out in the helper, you will get all the contents.

Returns:

  • (String)


73
74
75
76
77
# File 'lib/bootstrap3_helper/accordion_group.rb', line 73

def to_s
  content =  :div, id: @id, class: "panel-group #{@class}" do
    @content.call(self)
  end
end