Class: Bootstrap3Helper::Tabs::Menu

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

Overview

Used to rapidly generated Bootstrap Tabs Menu Components.

Examples:

Rendering out a Tabs::Menu component:

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

Instance Method Summary collapse

Methods inherited from Component

#concat, #content_tag, #parse_arguments, #uuid

Constructor Details

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

Creates a new Tabs::Menu object.

Parameters:

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

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

Options Hash (args):

  • type (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



19
20
21
22
23
24
25
26
# 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

Instance Method Details

Used to create menu items that are Dropdowns

Parameters:

  • name (String|Symbol)
  • args (Hash) (defaults to: {})

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)

Yield Parameters:



78
79
80
81
82
83
84
85
86
87
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 78

def dropdown(name, args = {}, &block)
  id       = args.fetch(:id, nil)
  data     = args.fetch(:data, nil)
  klass    = args.fetch(:class, '')
  dropdown = Tabs::Dropdown.new(@template, name, &block)

  content =  :li, id: id, class: 'dropdown' + klass, data: data do
    dropdown.to_s.html_safe
  end
end

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

Note:

You can opt out of passing in a block and the li will use the name attribute for the menu item.

Adds a new menu item to the object.

Parameters:

  • name (String|Symbol)

    Used to link nav li to tab-content

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

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)

Yield Returns:

  • (String)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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 = (
    :li,
    id:    id,
    class: klass,
    data:  data,
    role:  'presentation'
  ) do
    (
      :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_sString

Used to render out the contents of the menu.

Returns:

  • (String)


93
94
95
96
97
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 93

def to_s
   :ul, id: @id, class: "nav nav-#{@type} " + @class, role: 'tablist' do
    @content.call(self)
  end
end