Sha256: 081b88dd72e66f9999f88b67293d0491f0b2138e1a07371544816ca695fac1aa

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Kadmin
  module NavigationHelper
    # Generates HTML for a bootstrap navigation link
    # @param [String] title the navigation text
    # @param [Hash, String] path the path for the link
    # @param [Proc] block optional block to include content within the link
    def nav_link_to(title, path, &block)
      css_classes = []
      css_classes << 'active' if request.path.starts_with?(path)
      return content_tag(:li, link_to(title, path, &block), class: css_classes.join(' '))
    end

    # Generates a navigation drop down for bootstrap
    # @param [String] prompt dropdown prompt
    # @param [Array<Hash,String>] links list of links to add within the dropdown
    def dropdown(prompt, links = [])
      button_content = content_tag(:span, '', class: 'caret').prepend(prompt)
      button = button_tag(button_content, type: 'button', data: { toggle: 'dropdown' }, class: 'btn btn-sm')
      list = content_tag(:ul, '', class: 'dropdown-menu') do
        links.reduce(ActiveSupport::SafeBuffer.new) do |buffer, link|
          buffer + content_tag(:li, link)
        end
      end

      return content_tag(:div, button + list, class: 'dropdown', style: 'display: inline-block;')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kadmin-0.3.2 app/helpers/kadmin/navigation_helper.rb