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::Item component.
-
#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 26 |
# File 'lib/bootstrap5_helper/accordion.rb', line 16 def initialize(template, opts = {}, &block) super(template) @attrs = opts @id = @attrs.delete(:id) { uuid } @class = @attrs.delete(:class) { '' } @data = @attrs.delete(:data) { {} } @always_open = @attrs.delete(:always_open) { false } @flush = @attrs.delete(:flush) { false } @content = block || proc { '' } end |
Instance Method Details
#item(opts = {}, &block) ⇒ Accodion::Item
Used to generate a Accordion::Item component.
32 33 34 |
# File 'lib/bootstrap5_helper/accordion.rb', line 32 def item(opts = {}, &block) Accordion::Item.new(self, (@always_open ? nil : @id), opts, &block) end |
#to_s ⇒ String
String representation of the object.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bootstrap5_helper/accordion.rb', line 40 def to_s content_tag( :div, { id: @id, class: "accordion #{@flush ? 'accordion-flush' : ''} #{@class}", data: @data }.merge(@attrs) ) do @content.call(self) end end |