Sha256: c5415e8e6b5f8d117de9e5a05cc276e44ce696be42054d4abf43fcdc2d41365e

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module DropdownHelper
  # +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 %>
  #
  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

  # +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 %>
  #
  def activatable_li_tag_with_link(title, url, options = {})
    options[:class] = current_page?(url) ? "active #{options[:class]}" : options[:class]
    content_tag :li, link_to(title, url, {class: 'nav-link', target: options[:target]}), options
  end

  def caret_tag
    content_tag(:span, '', class: 'caret')
  end

  def dropdown_menu(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

  def dropdown_button(title, &block)
    link_to(h(title) + ' ' + caret_tag, '#',
            'data-toggle' => 'dropdown', class: 'btn dropdown-toggle') +
      content_tag(:ul, class: 'dropdown-menu', &block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kiso_themes-1.0.2 app/helpers/dropdown_helper.rb