Class: Bootstrap5Helper::Tab::Content

Inherits:
Component
  • Object
show all
Defined in:
lib/bootstrap5_helper/tab/content.rb

Overview

Build a Content component to be used with Tabs

Instance Method Summary collapse

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

Parameters:

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

Options Hash (opts):

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


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.

Parameters:

  • source (Symbol)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

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

Returns:

  • (String)


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)  { {} }

  (
    :div,
    {
      id:    id,
      class: "tab-pane #{klass}",
      role:  'tabpanel',
      data:  data
    }.merge(attrs),
    &block
  )
end

#to_sString

String representation of the object.

Returns:

  • (String)


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bootstrap5_helper/tab/content.rb', line 55

def to_s
  (
    :div,
    {
      id:    @id,
      class: "tab-content #{@class}",
      data:  @data
    }.merge(@attrs)
  ) do
    @content.call(self)
  end
end