Class: Bootstrap5Helper::CardWithNavTab

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

Overview

:nodoc:

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, context, opts) ⇒ CardWithNavTab #initialize(template, opts) ⇒ CardWithNavTab

Class constructor

Overloads:

  • #initialize(template, context, opts) ⇒ CardWithNavTab

    Parameters:

    • template (ActionView)
    • context (Symbol|String)
    • opts (Hash)

    Options Hash (opts):

    • :id (String)
    • :class (String)
    • :data (Hash)
  • #initialize(template, opts) ⇒ CardWithNavTab

    Parameters:

    • template (ActionView)
    • opts (Hash)

    Options Hash (opts):

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


20
21
22
23
24
25
26
27
28
29
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 20

def initialize(template, *context_or_options, &block)
  super(template)
  @context, args = parse_context_or_options(*context_or_options, {})

  @attrs   = args
  @id      = @attrs.delete(:id)    { '' }
  @class   = @attrs.delete(:class) { '' }
  @data    = @attrs.delete(:data)  { {} }
  @content = block || proc { '' }
end

Instance Method Details

#content(opts = {}, &block) ⇒ Tab::Content

Builds the Content object for the Tab.

Parameters:

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

Options Hash (opts):

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

Returns:



76
77
78
79
80
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 76

def content(opts = {}, &block)
   :div, class: 'card-body' do
    Tab::Content.new(@template, opts, &block).to_s
  end
end

Builds a custom Nav component for the tabs.

Overloads:

  • #nav(tag, opts) ⇒ Nav

    Parameters:

    • tag (Symbol|String)
      • :nav, :ul
    • opts (Hash)

    Options Hash (opts):

    • :id (String)
    • :class (String)
    • :data (Hash)
    • :child (Hash)
      • data attributes for child, NOT wrapper
  • #nav(opts) ⇒ Nav

    Parameters:

    • opts (Hash)

    Options Hash (opts):

    • :id (String)
    • :class (String)
    • :data (Hash)
    • :child (Hash)
      • data attributes for child, NOT wrapper

Yields:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 51

def nav(*tag_or_options, &block)
  tag, args       = parse_tag_or_options(*tag_or_options, {})
  args[:class]    = (args[:class]    || '') << ' nav-tabs card-header-tabs'
  args[:bs_attrs] = (args[:bs_attrs] || {}).merge(
    {
      data: {
        'bs-toggle'  => 'tab',
        'bs-display' => 'static'
      }
    }
  )

   :div, class: 'card-header' do
    Nav.new(@template, tag, args, &block).to_s
  end
end

#to_sObject

TODO:


85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 85

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