class Decidim::Menu
This class handles all logic regarding registering menus
Public Class Methods
new(name)
click to toggle source
# File lib/decidim/menu.rb, line 8 def initialize(name) @name = name @items = [] end
Public Instance Methods
build_for(context)
click to toggle source
Evaluates the registered configurations for this menu in a view context
# File lib/decidim/menu.rb, line 16 def build_for(context) registry.configurations.each do |configuration| context.instance_exec(self, &configuration) end end
item(label, url, options = {})
click to toggle source
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?
# File lib/decidim/menu.rb, line 44 def item(label, url, options = {}) @items << MenuItem.new(label, url, options) end
items()
click to toggle source
The weighted list of items in the menu
# File lib/decidim/menu.rb, line 51 def items @items.select(&:visible?).sort_by(&:position) end
Private Instance Methods
registry()
click to toggle source
# File lib/decidim/menu.rb, line 57 def registry @registry ||= MenuRegistry.find(@name) end