Sha256: 2dc8578ad68995be58564f3fc9b6443650428c6d7e5a0eebec1dd957975e47a9

Contents?: true

Size: 1.87 KB

Versions: 30

Compression:

Stored size: 1.87 KB

Contents

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

  private
  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 = nav_get_url(item)
    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|
      if defined?(SimpleNavigation)
        SimpleNavigation.config.autogenerate_item_ids = false
      end

      begin
        nav_extra_data_before(type, primary)
        items = nav_get_menu_items(type).select { |i| !i.name.blank? && i.enabled }
        roots = items.select { |i| i.parent_id.nil? }
        roots.each do |item|
          render_with_subs(items, primary, item)
        end
        nav_extra_data_after(type, primary)
      rescue Exception => exception
        Rails.logger.error exception.message
        Rails.logger.error exception.backtrace.join("\n")
        puts exception.message
        puts exception.backtrace.join("\n")
        capture_exception(exception) if respond_to?(:capture_exception)
        items
      end
    end
  end

  def nav_get_url(item)
    item.redirect.blank? ? item.fullpath : item.redirect
  end
  def nav_get_menu_items(type)
    ::Menu.find(type.to_s).pages.enabled.sorted.to_a
  end
  def nav_extra_data_before(type, primary)
    # override for additional config or items
  end
  def nav_extra_data_after(type, primary)
    # override for additional config or items
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rocket_cms-0.37.1 app/controllers/concerns/rs_menu.rb
rocket_cms-0.37.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.36.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.35.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.34.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.33.1 app/controllers/concerns/rs_menu.rb
rocket_cms-0.33.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.32.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.31.1 app/controllers/concerns/rs_menu.rb
rocket_cms-0.31.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.30.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.29.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.28.0 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.8 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.7 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.6 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.5 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.4 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.3 app/controllers/concerns/rs_menu.rb
rocket_cms-0.27.2 app/controllers/concerns/rs_menu.rb