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
# File 'lib/bootstrap5_helper/tab/content.rb', line 15

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

#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)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bootstrap5_helper/tab/content.rb', line 32

def pane(source, opts = {}, &block)
  id    = opts.fetch(:id,    source)
  klass = opts.fetch(:class, '')
  data  = opts.fetch(:data,  {})

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

#to_sString

String representation of the object.

Returns:

  • (String)


51
52
53
54
55
# File 'lib/bootstrap5_helper/tab/content.rb', line 51

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