Sha256: 58be1c8c271da65c2f35074258664e8cd4ce8e95efd2ebf79c5aa1741995d230

Contents?: true

Size: 835 Bytes

Versions: 25

Compression:

Stored size: 835 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, 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

25 entries across 25 versions & 1 rubygems

Version Path
tenon-1.0.40 app/helpers/tenon/nav_helper.rb
tenon-1.0.39 app/helpers/tenon/nav_helper.rb
tenon-1.0.38 app/helpers/tenon/nav_helper.rb
tenon-1.0.37 app/helpers/tenon/nav_helper.rb
tenon-1.0.36 app/helpers/tenon/nav_helper.rb
tenon-1.0.35 app/helpers/tenon/nav_helper.rb
tenon-1.0.33 app/helpers/tenon/nav_helper.rb
tenon-1.0.32 app/helpers/tenon/nav_helper.rb
tenon-1.0.31 app/helpers/tenon/nav_helper.rb
tenon-1.0.30 app/helpers/tenon/nav_helper.rb
tenon-1.0.29 app/helpers/tenon/nav_helper.rb
tenon-1.0.28 app/helpers/tenon/nav_helper.rb
tenon-1.0.27 app/helpers/tenon/nav_helper.rb
tenon-1.0.26 app/helpers/tenon/nav_helper.rb
tenon-1.0.25 app/helpers/tenon/nav_helper.rb
tenon-1.0.24 app/helpers/tenon/nav_helper.rb
tenon-1.0.23 app/helpers/tenon/nav_helper.rb
tenon-1.0.22 app/helpers/tenon/nav_helper.rb
tenon-1.0.21 app/helpers/tenon/nav_helper.rb
tenon-1.0.20 app/helpers/tenon/nav_helper.rb