Class: Bootstrap5Helper::Accordion
- 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
-
#initialize(template, opts = {}, &block) ⇒ Accordion
constructor
Class constructor.
-
#item(opts = {}, &block) ⇒ Accodion::Item
Used to generate a
Accordion::Itemcomponent. -
#to_s ⇒ String
String representation of the object.
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
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.
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_s ⇒ String
String representation of the object.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bootstrap5_helper/accordion.rb', line 39 def to_s content_tag( :div, id: @id, class: "accordion #{@flush ? 'accordion-flush' : ''} #{@class}", data: @data ) do @content.call(self) end end |