Module: RsMenu

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/rs_menu.rb

Instance Method Summary collapse

Instance Method Details



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/concerns/rs_menu.rb', line 29

def navigation(type)
  Proc.new do |primary|
    SimpleNavigation.config.autogenerate_item_ids = false
    begin
      items = ::Menu.find(type.to_s).pages.asc(:lft).to_a
      items.select { |i| i.parent_id.nil? && !i.name.blank? && i.enabled }.each do |item|
        render_with_subs(items, primary, item)
      end
    rescue Exception => exception
      Rails.logger.error exception.message
      Rails.logger.error exception.backtrace.join("\n")
      capture_exception(exception) if respond_to?(:capture_exception)
      items
    end
  end
end


20
21
22
23
24
25
26
27
# File 'app/controllers/concerns/rs_menu.rb', line 20

def navigation_item(primary, item, block=nil)
  url = item.redirect.blank? ? item.fullpath : item.redirect
  if block.nil?
    primary.item(item.slug, item.name, url, item.nav_options)
  else
    primary.item(item.slug, item.name, url, item.nav_options, &block)
  end
end

#render_with_subs(items, primary, item) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/concerns/rs_menu.rb', line 7

def render_with_subs(items, primary, item)
  subs = items.select { |i| i.parent_id == item.id && !i.name.blank? && i.enabled }
  if subs.empty?
    block = nil
  else
    block = Proc.new do |sub_nav|
      subs.each { |sub| render_with_subs(items, sub_nav, sub) }
    end
  end
  cr = item.clean_regexp
  navigation_item(primary, item, block)
end