Class: Maquina::Navbar::Menu

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ApplicationView
Defined in:
app/views/maquina/navbar/menu.rb

Overview

Navbar main Menu

Renders main navbar Menu. It can render menu for desktop o mobile versions.

Requires a Rails Helper method to get access to menu options. ‘menu_options` example:

def menu_options
  {
    home: root_path,
    users: users_path
    accounts: accounts_path
  }
end

‘Menu` uses I18n to translate menu options. Translation example:

menu:
  main:
    home: Inicio
    users: Usuarios
    accounts: Cuentas

‘Menu` is initialized by default to render links for desktop. To render mobile links initialize `Menu` as follow:

Views::Navbar::Menu.new(desktop: false)

Instance Method Summary collapse

Methods included from ApplicationView

#attribute_human_name, #button_to, #image_tag, #link_to, #model_human_name, #svg_icon

Constructor Details

#initialize(desktop: true) ⇒ Menu

Returns a new instance of Menu.



36
37
38
# File 'app/views/maquina/navbar/menu.rb', line 36

def initialize(desktop: true)
  @desktop = desktop
end

Instance Method Details

#view_templateObject



40
41
42
43
44
45
46
# File 'app/views/maquina/navbar/menu.rb', line 40

def view_template
  div class: "#{link_type}-menu" do
    secure_menu_options.each_pair do |option, path|
      render(Maquina::Navbar::MenuItemLink.new(option, path, desktop: @desktop))
    end
  end
end