class Bootstrap4Helper::Tab

Builds a Tab component.

Public Class Methods

new(template, opts = {}, &block) click to toggle source

Class constructor

@note The support types are: `:tabs` and `:pills`

@param [ActionView] template @param [Hash] opts @option opts [Symbol] :type @option opts [String] :id @option opts [String] :class @option opts [Hash] :data

Calls superclass method Bootstrap4Helper::Component::new
# File lib/bootstrap4_helper/tab.rb, line 17
def initialize(template, opts = {}, &block)
  super(template)

  @type    = opts.fetch(:type,  :tabs)
  @id      = opts.fetch(:id,    uuid)
  @class   = opts.fetch(:class, '')
  @data    = opts.fetch(:data,  {})
  @content = block || proc { '' }
end

Public Instance Methods

content(opts = {}, &block) click to toggle source

Builds the Content object for the Tab.

@param [Hash] opts @option opts [String] :id @option opts [String] :class @option opts [Hash] :data @return [Tab::Content]

# File lib/bootstrap4_helper/tab.rb, line 54
def content(opts = {}, &block)
  Content.new(@template, opts, &block)
end
nav(opts = {}, &block) click to toggle source

Builds a custom Nav component for the tabs.

@param [Hash] opts @option opts [String] :class @option opts [Hash] :data @return [Nav]

to_s() click to toggle source

This has a weird interaction. Because this object doesn't actually return any wrapping string or DOM element, we want to return nil, so that only the output buffer on the sub components are returned. If we return the return value of the block, we will get the last element added to the input buffer as an unescaped string.

# File lib/bootstrap4_helper/tab.rb, line 64
def to_s
  @content.call(self)

  nil
end