Module: Bootstrap::DropdownHelper

Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/helpers/bootstrap/dropdown_helper.rb

Overview

Examples:

nav dropdown

<%= nav_dropdown('Admin') do %>
  <%= dropdown_item('Users', '/admin/users') %>
  <%= dropdown_item('Logs', '/admin/logs') %>
  <%= dropdown_divider %>
  <%= dropdown_item('Exceptions', '/admin/exceptions') %>
<% end %>

button dropdown

<%= button_dropdown('Actions') do %>
  <%= dropdown_item('Action 1', '/action1') %>
  <%= dropdown_item('Action 2', '/action2') %>
<% end %>

split-button dropdown

<%= split_button_dropdown('Default', url: '/default') do %>
  <%= dropdown_item('Action 1', '/action1') %>
  <%= dropdown_item('Action 2', '/action2') %>
<% end %>#

Instance Method Summary collapse

Instance Method Details

#button_dropdown('Text') ⇒ Object #button_dropdown('Text', : info) ⇒ Object #button_dropdown('Text', : info, : mini) ⇒ Object

Returns a Bootstrap button dropdown

Parameters have same semantics as in ButtonHelper#button

Yields:

  • yielded block is usually calls to NavHelper#dropdown_item or NavHelper#dropdown_divider# @return [String]



53
54
55
56
57
# File 'app/helpers/bootstrap/dropdown_helper.rb', line 53

def button_dropdown(*args)
  (:div, class: 'btn-group') do
    button_dropdown_link(*args) + dropdown_ul { yield }
  end
end

Returns a divider for various dropdowns

Returns:

  • (String)

    <li class=“divider”>



95
96
97
# File 'app/helpers/bootstrap/dropdown_helper.rb', line 95

def dropdown_divider
  (:li, nil, class: 'divider')
end

Returns a link for use within various *_dropdown methods

Returns:

  • (String)


81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/bootstrap/dropdown_helper.rb', line 81

def dropdown_item(*args)
  options = args.extract_options!
  text = args.shift or raise "Need text to link to"
  url = args.shift || 'javascript:void(0)'
  
  options = ensure_class(options, 'dropdown')

  (:li) do
    link_to(text, url, options)
  end
end

Returns a drop-down menu of links

Usually called from yielded block of NavHelper#nav_bar

Parameters:

  • text (String)

    text of dropdown link

Yields:

  • yielded block is usually calls to NavHelper#dropdown_item or NavHelper#dropdown_divider

Returns:

  • (String)

    ‘<li class=’dropdown’><ul class=‘dropdown-menu’> with contents of yielded block



36
37
38
39
40
41
42
43
# File 'app/helpers/bootstrap/dropdown_helper.rb', line 36

def nav_dropdown(text, options={})
  options = canonicalize_options(options)
  options = ensure_class(options, 'nav-item dropdown')
  
  (:li, options) do
    nav_dropdown_link(text) + dropdown_ul { yield }
  end
end

#split_button_dropdown('Text') ⇒ String #split_button_dropdown('Text', url: '/url') ⇒ String #split_button_dropdown('Text', : large, : danger, url: '/url') ⇒ String

Returns a Bootstrap split-button dropdown

Parameters have same semantics as in ButtonHelper#button

Yields:

  • yielded block is usually calls to NavHelper#dropdown_item or NavHelper#dropdown_divider

Returns:

  • (String)


68
69
70
71
72
73
74
# File 'app/helpers/bootstrap/dropdown_helper.rb', line 68

def split_button_dropdown(*args)
  extras = extract_extras(*args)
  
  (:div, class: 'btn-group') do
    split_button_dropdown_default(*args) + split_button_dropdown_toggle(extras) + dropdown_ul { yield }
  end
end