Class: Decidim::MenuItemPresenter

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

Overview

A presenter to render menu items

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 'decidim-core/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

#renderObject


28
29
30
31
32
33
34
35
# File 'decidim-core/app/presenters/decidim/menu_item_presenter.rb', line 28

def render
   :li, class: link_wrapper_classes do
    output = [link_to(composed_label, url)]
    output.push(@view.send(:simple_menu, @menu_item.submenu).render) if @menu_item.submenu

    safe_join(output)
  end
end