Sha256: c598bc1b0476ad4b679a357e6a5472eb1481c6b5bc280ac426584619f6e07f12

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 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) if primary
        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

17 entries across 17 versions & 1 rubygems

Version Path
ack_rocket_cms-0.7.6.4 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.6.3 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.6.2 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.6.1 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.6 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.5.2 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.5.1 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.5 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.4.1 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.4 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.3 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.4 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.3.2 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.3.1 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.3 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.2 app/controllers/concerns/rs_menu.rb
ack_rocket_cms-0.7.2.1 app/controllers/concerns/rs_menu.rb