Sha256: a27e425c13916f4aa2d5837b4e659b10ad2594a380bfea618d4d043265c9cbf8

Contents?: true

Size: 1.67 KB

Versions: 50

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module Decidim
  #
  # This class handles all logic regarding registering menus
  #
  class Menu
    def initialize(name)
      @name = name
      @items = []
    end

    #
    # Evaluates the registered configurations for this menu in a view context
    #
    def build_for(context)
      registry.configurations.each do |configuration|
        context.instance_exec(self, &configuration)
      end
    end

    # Public: Registers a new item for the menu
    #
    # @param label [String, Symbol] A compulsory label for the menu item
    # @param url [String, Symbol] The URL this item will link to
    # @param options [Hash] The options for the menu item
    #
    # @option options [Float] :position
    #         The lower the position, the earlier in the menu the item will
    #         be displayed.  Default: Float::INFINITY
    #
    # @option options [Symbol, Proc] :if
    #         Decides whether the menu item will be displayed. Evaluated on
    #         each request.
    #
    # @example
    #
    #   menu.item "My Resource", "/resources"
    #   menu.item I18n.t("menu.meetings"), decidim_meetings.root_path
    #   menu.item current_user.username, decidim.profile_path(current_user.nickname)
    #   menu.item "Gestor de Procesos", "/processes", active: :exact
    #   menu.item "Gestor de Procesos", "/processes", if: admin?
    #
    def item(label, url, options = {})
      @items << MenuItem.new(label, url, options)
    end

    #
    # The weighted list of items in the menu
    #
    def items
      @items.select(&:visible?).sort_by(&:position)
    end

    private

    def registry
      @registry ||= MenuRegistry.find(@name)
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
decidim-core-0.24.3 lib/decidim/menu.rb
decidim-core-0.23.6 lib/decidim/menu.rb
decidim-core-0.24.2 lib/decidim/menu.rb
decidim-core-0.23.5 lib/decidim/menu.rb
decidim-core-0.24.1 lib/decidim/menu.rb
decidim-core-0.24.0 lib/decidim/menu.rb
decidim-core-0.24.0.rc2 lib/decidim/menu.rb
decidim-core-0.23.4 lib/decidim/menu.rb
decidim-core-0.24.0.rc1 lib/decidim/menu.rb
decidim-core-0.23.3 lib/decidim/menu.rb
decidim-core-0.23.2 lib/decidim/menu.rb
decidim-core-0.23.1 lib/decidim/menu.rb
decidim-core-0.23.1.rc1 lib/decidim/menu.rb
decidim-core-0.23.0 lib/decidim/menu.rb
decidim-core-0.22.0 lib/decidim/menu.rb
decidim-core-0.21.0 lib/decidim/menu.rb
decidim-core-0.20.1 lib/decidim/menu.rb
decidim-core-0.20.0 lib/decidim/menu.rb
decidim-core-0.19.1 lib/decidim/menu.rb
decidim-core-0.18.1 lib/decidim/menu.rb