Module: WcmsComponents::NavigationHelper

Defined in:
app/helpers/wcms_components/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details

Gets used by the side menu / page navigation



28
29
30
# File 'app/helpers/wcms_components/navigation_helper.rb', line 28

def menu_block(html_options = {}, &block)
  MenuBlock.new(self, html_options).render(&block)
end

Set class on active navigation items



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/wcms_components/navigation_helper.rb', line 5

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]
      (:li, :class => "descendant active") do
        link_to( text, real_path)
      end
    else
      (:li, :class => "descendant") do
        link_to( text, real_path)
      end
    end
  end
end