Class: Decidim::MenuItemPresenter

Inherits:
Object
  • Object
show all
Defined in:
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
24
# File 'app/presenters/decidim/menu_item_presenter.rb', line 19

def initialize(menu_item, view, options = {})
  @menu_item = menu_item
  @view = view
  @element_class = options[:element_class]
  @active_class = options[:active_class]
end

Instance Method Details

#renderObject



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

def render
   :li, class: link_wrapper_classes do
    if icon_name
      link_to(url) { icon(icon_name) + label }
    else
      link_to label, url
    end
  end
end