Class: Decidim::MenuPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/decidim/menu_presenter.rb

Overview

A presenter to render menus

Instance Method Summary collapse

Constructor Details

#initialize(name, view, options = {}) ⇒ MenuPresenter

Initializes a menu for presentation

Parameters:

  • name (Symbol)

    The name of the menu registry to be rendered

  • view (ActionView::Base)

    The view scope to render the menu

  • options (Hash) (defaults to: {})

    The rendering options for the menu entries



13
14
15
16
17
# File 'app/presenters/decidim/menu_presenter.rb', line 13

def initialize(name, view, options = {})
  @name = name
  @view = view
  @options = options
end

Instance Method Details

#active_itemObject



30
31
32
# File 'app/presenters/decidim/menu_presenter.rb', line 30

def active_item
  presented_items.find(&:active?)
end

#evaluated_menuObject



22
23
24
25
26
27
28
# File 'app/presenters/decidim/menu_presenter.rb', line 22

def evaluated_menu
  @evaluated_menu ||= begin
    menu = Menu.new(@name)
    menu.build_for(@view)
    menu
  end
end

#renderObject



34
35
36
37
38
# File 'app/presenters/decidim/menu_presenter.rb', line 34

def render
   :nav, class: "main-nav", "aria-label": @options.fetch(:label, nil) do
    render_menu
  end
end