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-core-0.7.4 app/presenters/decidim/menu_presenter.rb
decidim-core-0.7.3 app/presenters/decidim/menu_presenter.rb
decidim-core-0.7.2 app/presenters/decidim/menu_presenter.rb
decidim-core-0.7.1 app/presenters/decidim/menu_presenter.rb
decidim-core-0.7.0 app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.8 app/presenters/decidim/menu_presenter.rb
decidim-0.6.8 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.7 app/presenters/decidim/menu_presenter.rb
decidim-0.6.7 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.6 app/presenters/decidim/menu_presenter.rb
decidim-0.6.6 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.5 app/presenters/decidim/menu_presenter.rb
decidim-0.6.5 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.4 app/presenters/decidim/menu_presenter.rb
decidim-0.6.4 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.3 app/presenters/decidim/menu_presenter.rb
decidim-0.6.3 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.2 app/presenters/decidim/menu_presenter.rb
decidim-0.6.2 decidim-core/app/presenters/decidim/menu_presenter.rb
decidim-core-0.6.1 app/presenters/decidim/menu_presenter.rb