Module: DropdownHelper
- Defined in:
- app/helpers/dropdown_helper.rb
Instance Method Summary collapse
-
#activatable_li_tag(url, css_class = '', &block) ⇒ Object
li
tag with the ‘active’ class added if the url is the current one. -
#activatable_li_tag_with_link(title, url, options = {}) ⇒ Object
li
tag with the ‘active’ class added if the url is the current one with a link inside it pointing to that url. - #caret_tag ⇒ Object
- #dropdown_button(title, &block) ⇒ Object
- #dropdown_menu(title, &block) ⇒ Object
Instance Method Details
#activatable_li_tag(url, css_class = '', &block) ⇒ Object
li
tag with the ‘active’ class added if the url is the current one. Good for navbar and dropdowns. Eg.:
<%= activatable_li_tag users_path do |url| %>
<%= link_to "Users", url %>
<% end %>
10 11 12 13 |
# File 'app/helpers/dropdown_helper.rb', line 10 def activatable_li_tag(url, css_class = '', &block) css_class = current_page?(url) ? "active #{css_class}" : css_class content_tag :li, capture(url, &block), class: css_class end |
#activatable_li_tag_with_link(title, url, options = {}) ⇒ Object
li
tag with the ‘active’ class added if the url is the current one with a link inside it pointing to that url. Good for navbar and dropdowns. Eg.:
<%= activatable_li_tag_with_link "Users", users_path %>
Same as:
<%= activatable_li_tag users_path do |url| %>
<%= link_to "Users", url %>
<% end %>
28 29 30 31 |
# File 'app/helpers/dropdown_helper.rb', line 28 def activatable_li_tag_with_link(title, url, = {}) [:class] = current_page?(url) ? "active #{[:class]}" : [:class] content_tag :li, link_to(title, url, {class: 'nav-link', target: [:target]}), end |
#caret_tag ⇒ Object
33 34 35 |
# File 'app/helpers/dropdown_helper.rb', line 33 def caret_tag content_tag(:span, '', class: 'caret') end |
#dropdown_button(title, &block) ⇒ Object
45 46 47 48 49 |
# File 'app/helpers/dropdown_helper.rb', line 45 def (title, &block) link_to(h(title) + ' ' + caret_tag, '#', 'data-toggle' => 'dropdown', class: 'btn dropdown-toggle') + content_tag(:ul, class: 'dropdown-menu', &block) end |
#dropdown_menu(title, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/helpers/dropdown_helper.rb', line 37 def (title, &block) content_tag :li, class: 'dropdown' do link_to(h(title) + ' ' + caret_tag, '#', 'data-toggle' => 'dropdown', class: 'dropdown-toggle') + content_tag(:ul, class: 'dropdown-menu', &block) end end |