Class: Bootstrap3Helper::Tabs

Inherits:
Component show all
Defined in:
lib/bootstrap3_helper/tabs.rb,
lib/bootstrap3_helper/tabs/menu.rb,
lib/bootstrap3_helper/tabs/content.rb,
lib/bootstrap3_helper/tabs/dropdown.rb

Overview

Note:

On menu items - you can pass in either symbol or string for the link. If you pass in a block, it will use the block for the title of the li. If no block is present, then it will titleize the symbol or string.

Tabs::Menu will respond to item and dropdown Each method will yield the corresponding component, either a Tabs::Menu or a Tabs::Dropdown.

Used to rapidly generated Bootstrap Tabs Components.

Examples:

Rendering out a Bootstrap Tab components in a view:

<%= tabs_helper type: :pills do |menu, content| %>
  <%= menu.item(:testing1, class: 'active') { ' Testing 1' } %>
  <%= menu.item :testing2 %>
  <%= menu.item(:testing3) { ' Testing 3' } %>
  <%= menu.dropdown 'Testing Dropdown' do |dropdown| %>
      <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
      <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
      <%= dropdown.item(:testing7 ) { 'Testing 7' } %>
  <% end %>

  <%= content.item :testing1, class: 'active' do %>
      Testing 1 content
  <% end %>
  <%= content.item :testing2 do %>
      Testing 2 content
  <% end %>
  <%= content.item :testing3 do %>
      Testing 3 content
  <% end %>
  <%= content.item :testing5 do %>
      Testing 5 content
  <% end %>
  <%= content.item :testing6 do %>
      Testing 6 content
  <% end %>
  <%= content.item :testing7 do %>
      Testing 7 content
  <% end %>
<% end %>

Defined Under Namespace

Classes: Content, Dropdown, Menu

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) ⇒ Tabs

Creates a new Tabs object.

Parameters:

  • template (ActionView)
    • Template in which your are binding too.

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

Options Hash (args):

  • :type (String|Symbol)

    Used to tell the helper which tab version - :tabs|:pills

  • :id (String)

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

  • :class (String)

    Custom class for the parent container.



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

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

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

Instance Method Details

#content(args = {}, &block) ⇒ Tabs::Content

Allows you to access the Tabs::Content object

Returns:

See Also:



75
76
77
# File 'lib/bootstrap3_helper/tabs.rb', line 75

def content(args = {}, &block)
  Tabs::Content.new(@template, args, &block)
end

Allows you access the Tabs::Menu object.

Returns:

See Also:



66
67
68
# File 'lib/bootstrap3_helper/tabs.rb', line 66

def menu(args = {}, &block)
  Tabs::Menu.new(@template, args.merge(type: @type), &block)
end

#to_sString

Used to render out the HTML of the Tabs Object

Returns:

  • (String)


83
84
85
86
87
# File 'lib/bootstrap3_helper/tabs.rb', line 83

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