Sha256: 604bcf0607a02e4edf51560bad5b260faf0d75dfff331bdd8b0e56a579436466

Contents?: true

Size: 841 Bytes

Versions: 19

Compression:

Stored size: 841 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 fa-2x")
      content += text
      opts[:class] ||= ''
      opts[:title] ||= text
      opts[:class] += " #{active_class(path, opts[:active])}"
      link_to(content, path, opts)
    end

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
tenon-1.0.60 app/helpers/tenon/nav_helper.rb
tenon-1.0.59 app/helpers/tenon/nav_helper.rb
tenon-1.0.57 app/helpers/tenon/nav_helper.rb
tenon-1.0.56 app/helpers/tenon/nav_helper.rb
tenon-1.0.55 app/helpers/tenon/nav_helper.rb
tenon-1.0.54 app/helpers/tenon/nav_helper.rb
tenon-1.0.53 app/helpers/tenon/nav_helper.rb
tenon-1.0.52 app/helpers/tenon/nav_helper.rb
tenon-1.0.51 app/helpers/tenon/nav_helper.rb
tenon-1.0.50 app/helpers/tenon/nav_helper.rb
tenon-1.0.49 app/helpers/tenon/nav_helper.rb
tenon-1.0.48 app/helpers/tenon/nav_helper.rb
tenon-1.0.47 app/helpers/tenon/nav_helper.rb
tenon-1.0.46 app/helpers/tenon/nav_helper.rb
tenon-1.0.45 app/helpers/tenon/nav_helper.rb
tenon-1.0.44 app/helpers/tenon/nav_helper.rb
tenon-1.0.43 app/helpers/tenon/nav_helper.rb
tenon-1.0.42 app/helpers/tenon/nav_helper.rb
tenon-1.0.41 app/helpers/tenon/nav_helper.rb