Sha256: ca8f65075370bd6997e27a0f1d5963e4b28dd8db52ebada4aabaa762d089e771

Contents?: true

Size: 1.32 KB

Versions: 42

Compression:

Stored size: 1.32 KB

Contents

module RsMenu
  extend ActiveSupport::Concern
  included do
    helper_method :navigation
  end

  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
  
  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

  def navigation(type)
    Proc.new do |primary|
      SimpleNavigation.config.autogenerate_item_ids = false
      begin
        items = ::Menu.find(type.to_s).pages.enabled.sorted.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
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
rocket_cms-0.6.17 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.16 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.15 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.14 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.13 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.12 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.11 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.10 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.9 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.8 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.7 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.6 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.5 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.4 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.3 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.2 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.1 app/controllers/concerns/rs_menu.rb
rocket_cms-0.6.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.5.24 app/controllers/concerns/rs_menu.rb
rocket_cms-0.5.23 app/controllers/concerns/rs_menu.rb