Sha256: 9b32e4a016152d94679be2e41fd3527123a8c3acdbf611a6710b4439ce158b2d

Contents?: true

Size: 1.09 KB

Versions: 36

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  # A presenter to render menus
  class MenuPresenter
    #
    # Initializes a menu for presentation
    #
    # @param name [Symbol] The name of the menu registry to be rendered
    # @param view [ActionView::Base] The view scope to render the menu
    # @param options [Hash] The rendering options for the menu entries
    #
    def initialize(name, view, options = {})
      @name = name
      @view = view

      @options = options
    end

    delegate :items, to: :evaluated_menu
    delegate :content_tag, :safe_join, to: :@view

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

    def render
      content_tag :nav, class: "main-nav" do
        content_tag :ul do
          safe_join(menu_items)
        end
      end
    end

    private

    def menu_items
      items.map do |menu_item|
        MenuItemPresenter.new(menu_item, @view, @options).render
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
decidim-0.6.1 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.0 app/presenters/decidim/menu_presenter.rb
decidim-0.6.0 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.5.1 app/presenters/decidim/menu_presenter.rb
decidim-0.5.1 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.5.0 app/presenters/decidim/menu_presenter.rb
decidim-0.5.0 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.4.4 app/presenters/decidim/menu_presenter.rb
decidim-core-0.4.2 app/presenters/decidim/menu_presenter.rb
decidim-core-0.4.1 app/presenters/decidim/menu_presenter.rb
decidim-core-0.4.3 app/presenters/decidim/menu_presenter.rb
decidim-core-0.4.0 app/presenters/decidim/menu_presenter.rb
decidim-core-0.3.2 app/presenters/decidim/menu_presenter.rb
decidim-core-0.3.1 app/presenters/decidim/menu_presenter.rb
decidim-core-0.3.0 app/presenters/decidim/menu_presenter.rb
decidim-core-0.2.0 app/presenters/decidim/menu_presenter.rb