Sha256: c1212677c96b04f199d884858760b735bd111494d0ca86cd871547830909d94a

Contents?: true

Size: 802 Bytes

Versions: 15

Compression:

Stored size: 802 Bytes

Contents

module Tenon
  module NavHelper
    def nav_item(text, path_object, icon_class, link_opts = {})
      path = path(path_object)
      content = link(text, path, icon_class, link_opts)
      content_tag(:li, content)
    end

    private

    def path(path_object)
      if path_object.is_a?(Class)
        path_object
      else
        path_object
      end
    end

    def link(text, path, icon_class, opts = {})
      content = content_tag(:i, '', class: "fa fa-#{icon_class} fa-fw")
      content += text
      opts[:class] ||= ''
      opts[:title] ||= text
      opts[:class] += " #{active_class(path)}"
      link_to(content, path, opts)
    end

    def active_class(path)
      path = url_for(path).split('/')[0..2].join('/')[1..-1]
      'active' if path == controller_path
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tenon-1.0.14 app/helpers/tenon/nav_helper.rb
tenon-1.0.13 app/helpers/tenon/nav_helper.rb
tenon-1.0.12 app/helpers/tenon/nav_helper.rb
tenon-1.0.11 app/helpers/tenon/nav_helper.rb
tenon-1.0.10 app/helpers/tenon/nav_helper.rb
tenon-1.0.9 app/helpers/tenon/nav_helper.rb
tenon-1.0.8 app/helpers/tenon/nav_helper.rb
tenon-1.0.7 app/helpers/tenon/nav_helper.rb
tenon-1.0.6 app/helpers/tenon/nav_helper.rb
tenon-1.0.5 app/helpers/tenon/nav_helper.rb
tenon-1.0.4 app/helpers/tenon/nav_helper.rb
tenon-1.0.3 app/helpers/tenon/nav_helper.rb
tenon-1.0.2 app/helpers/tenon/nav_helper.rb
tenon-1.0.1 app/helpers/tenon/nav_helper.rb
tenon-1.0 app/helpers/tenon/nav_helper.rb