Sha256: b1a3158cf5282cd385e1afcb3589360bec84b71677562478f56833d2f8220d19

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module WcmsComponents
  module NavigationHelper

    # Set class on active navigation items
    def nav_link(text, path_helper)
      # The router can't match against a relative root in the path
      # so we need to strip it out with script_name: ''.
      # Note: passing nil as the script_name does not work
      router_path = send(path_helper, script_name: '')
      real_path = send(path_helper)

      recognized = ::Rails.application.routes.recognize_path(router_path)

      if policy(recognized[:controller].classify.constantize).index?  # make sure user has permission to index this controller
        if recognized[:controller] == params[:controller] # && recognized[:action] == params[:action]
          content_tag(:li, :class => "descendant active") do
            link_to( text, real_path)
          end
        else
          content_tag(:li, :class => "descendant") do
            link_to( text, real_path)
          end
        end
      end
    end

    # Gets used by the side menu / page navigation
    def menu_block(html_options = {}, &block)
      MenuBlock.new(self, html_options).render(&block)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
biola_wcms_components-0.25.4 app/helpers/wcms_components/navigation_helper.rb
biola_wcms_components-0.25.3 app/helpers/wcms_components/navigation_helper.rb
biola_wcms_components-0.25.2 app/helpers/wcms_components/navigation_helper.rb
biola_wcms_components-0.25.1 app/helpers/wcms_components/navigation_helper.rb
biola_wcms_components-0.25.0 app/helpers/wcms_components/navigation_helper.rb
biola_wcms_components-0.24.3 app/helpers/wcms_components/navigation_helper.rb