Class: Bootstrap3Helper::Tabs::Content

Inherits:
Component
  • Object
show all
Defined in:
lib/bootstrap3_helper/tabs/content.rb

Overview

Used to rapidly generated Bootstrap Tabs Content Components.

Instance Method Summary collapse

Methods inherited from Component

#concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #uuid

Constructor Details

#initialize(template, args = {}, &block) ⇒ Content

Creates a new Tabs::Menu object.

Parameters:

  • template (ActionView)

    Template in which your are binding too.

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

Options Hash (args):

  • :id (String)

    The ID, if you want one, for the parent container.

  • :class (String)

    Custom class for the parent container.

  • :data (Hash)

    Any data attributes you want on the parent element.



15
16
17
18
19
20
21
22
# File 'lib/bootstrap3_helper/tabs/content.rb', line 15

def initialize(template, args = {}, &block)
  super(template)

  @id      = args.fetch(:id,    nil)
  @class   = args.fetch(:class, '')
  @data    = args.fetch(:data,  {})
  @content = block || proc { '' }
end

Instance Method Details

#pane(name, args = {}) ⇒ Object

Adds a new tabe pane item to the object.

Parameters:

  • name (String|Symbol)
    • Used to link to the nav menu item.

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

Options Hash (args):

  • :class (String)

    Custom class for the pane.

  • :data (Hash)

    Any data attributes you want on the pane element.

Yield Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bootstrap3_helper/tabs/content.rb', line 32

def pane(name, args = {})
  data   = args.fetch(:data, nil)
  klass  = args.fetch(:class, '')
  active = klass.include? 'active'

  (
    :div,
    id:       name,
    class:    "tab-pane fade #{active ? 'in' : ''} #{klass}",
    aria:     { hidden: active },
    data:     data,
    role:     'tabpanel',
    tabindex: -1
  ) do
    yield if block_given?
  end
end

#to_sString

Used to render out the object as HTML

Returns:

  • (String)


54
55
56
57
58
# File 'lib/bootstrap3_helper/tabs/content.rb', line 54

def to_s
   :div, id: @id, class: 'tab-content' + @class do
    @content.call(self)
  end
end