Class: Decidim::MenuItemPresenter

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

Overview

A presenter to render menu items

Direct Known Subclasses

BreadcrumbRootMenuItemPresenter

Instance Method Summary collapse

Constructor Details

#initialize(menu_item, view, options = {}) ⇒ MenuItemPresenter

Initializes a menu item for presentation

Parameters:

  • menu_item (MenuItem)

    The menu item itself

  • view (ActionView::Base)

    The view instance to help rendering the item

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

    The rendering options for the item

Options Hash (options):

  • :element_class (String)

    The CSS class to be used for the item

  • :active_class (String)

    The CSS class to be used for the active item



19
20
21
22
23
# File 'app/presenters/decidim/menu_item_presenter.rb', line 19

def initialize(menu_item, view, options = {})
  @menu_item = menu_item
  @view = view
  @options = OpenStruct.new(options)
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/presenters/decidim/menu_item_presenter.rb', line 41

def active?
  is_active_link?(url, active)
end

#renderObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/presenters/decidim/menu_item_presenter.rb', line 28

def render
   :li, role: :menuitem, class: link_wrapper_classes do
    output = if url == "#"
               [(:span, composed_label, class: "sidebar-menu__item-disabled")]
             else
               [link_to(composed_label, url, link_options)]
             end
    output.push(@view.send(:simple_menu, **@menu_item.submenu).render) if @menu_item.submenu

    safe_join(output)
  end
end