class Bootstrap3Helper::Tabs::Menu

Used to rapidly generated Bootstrap Tabs Menu Components.

@example Rendering out a Tabs::Menu component:

<code>
  <% menu.item(:testing3) { ' Testing 3' } %>
</code>

Public Class Methods

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

Creates a new Tabs::Menu object.

@param [ActionView] template - Template in which your are binding too. @param [Hash] args @option args [Symbol] type Used to tell the helper which tab version :tabs|:pills @option args [String] id The ID, if you want one, for the parent container @option args [String] class Custom class for the parent container

Calls superclass method Bootstrap3Helper::Component::new
# File lib/bootstrap3_helper/tabs/menu.rb, line 19
def initialize(template, args = {}, &block)
  super(template)

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

Public Instance Methods

dropdown(name, args = {}, &block) click to toggle source

Used to create menu items that are Dropdowns

@param [String|Symbol] name @param [Hash] args @option args [String] :id @option args [String] :class @option args [Hash] :data @yieldparam dropdown [Tabs::Dropdown]

item(name, args = {}) { |: name.titleize| ... } click to toggle source

Adds a new menu item to the object.

@note You can opt out of passing in a block and the li will use

the name attribute for the menu item.

@param [String|Symbol] name Used to link nav li to tab-content @param [Hash] args @option args [String] :id @option args [String] :class @option args [Hash] :data @yieldreturn [String]

# File lib/bootstrap3_helper/tabs/menu.rb, line 42
def item(name, args = {})
  id     = args.fetch(:id, nil)
  data   = args.fetch(:data, nil)
  klass  = args.fetch(:class, '')
  active = klass.include? 'active'

  li = content_tag(
    :li,
    id:    id,
    class: klass,
    data:  data,
    role:  'presentation'
  ) do
    content_tag(
      :a,
      href:     "##{name}",
      role:     'tab',
      tabindex: -1,
      data:     { toggle: 'tab' },
      aria:     { controls: "##{name}", expanded: active, selected: active }
    ) do
      block_given? ? yield : name.to_s.titleize
    end
  end
end
to_s() click to toggle source

Used to render out the contents of the menu.

@return [String]

# File lib/bootstrap3_helper/tabs/menu.rb, line 93
def to_s
  content_tag :ul, id: @id, class: "nav nav-#{@type} " + @class, role: 'tablist' do
    @content.call(self)
  end
end