Class: Bootstrap5Helper::Tab::Content
- Defined in:
- lib/bootstrap5_helper/tab/content.rb
Overview
Build a Content component to be used with Tabs
Instance Method Summary collapse
-
#initialize(template, opts = {}, &block) ⇒ Content
constructor
Class constructor.
-
#pane(source, opts = {}, &block) ⇒ String
Builds the pane for the tab.
-
#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) ⇒ Content
Class constructor
15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap5_helper/tab/content.rb', line 15 def initialize(template, opts = {}, &block) super(template) @attrs = opts @id = @attrs.delete(:id) { uuid } @class = @attrs.delete(:class) { '' } @data = @attrs.delete(:data) { {} } @content = block || proc { '' } end |
Instance Method Details
#pane(source, opts = {}, &block) ⇒ String
Builds the pane for the tab.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bootstrap5_helper/tab/content.rb', line 33 def pane(source, opts = {}, &block) attrs = opts id = attrs.delete(:id) { source } klass = attrs.delete(:class) { '' } data = attrs.delete(:data) { {} } content_tag( :div, { id: id, class: "tab-pane #{klass}", role: 'tabpanel', data: data }.merge(attrs), &block ) end |
#to_s ⇒ String
String representation of the object.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bootstrap5_helper/tab/content.rb', line 55 def to_s content_tag( :div, { id: @id, class: "tab-content #{@class}", data: @data }.merge(@attrs) ) do @content.call(self) end end |