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
# 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, {})
  @id      = args.fetch(:id,    '')
  @class   = args.fetch(:class, '')
  @data    = args.fetch(:data,  nil)
  @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:



73
74
75
76
77
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 73

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:



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

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[:data]    = (args[:data]  || {}).merge('bs-toggle' => 'tab')
  args[:child]   = (args[:child] || {}).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:


82
83
84
85
86
87
88
89
90
91
# File 'lib/bootstrap5_helper/card_with_nav_tab.rb', line 82

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