Class: Layout::NavbarComponent
- Inherits:
-
CommonComponent
- Object
- ViewComponent::Base
- CommonComponent
- Layout::NavbarComponent
- Defined in:
- app/components/layout/navbar_component.rb
Overview
This class manage the site navbar generation (id: nav3)
Instance Method Summary collapse
-
#admin_submenu ⇒ Array
Admin menu entries.
-
#call ⇒ String
Generate an html safe string with full ispra top menu.
-
#editor_submenu ⇒ Array
Admin menu entries.
-
#initialize(user: nil) ⇒ NavbarComponent
constructor
A new instance of NavbarComponent.
-
#lang_submenu ⇒ Object
Generate the ‘select language’ submenu html block.
-
#navbar ⇒ Object
render Bulmacomp::NavbarComponent with the options.
-
#navbar_end ⇒ Object
Generate the navbar-end html block.
-
#navbar_start ⇒ Object
Gerate the navbar-start html block.
-
#navbar_title ⇒ Object
Generate the navbar-title html block.
- #submenu(title:, sub:) ⇒ Object
-
#user_submenu ⇒ Object
Generate the user submenu html block.
Methods inherited from CommonComponent
#icon, #icon_text, #level, #level_item, #pagy, #turbo_yield
Methods included from ApplicationHelper
#fas_icon, #icon, #icon_text, #l_date, #l_long, #l_time, #notifications, #notify, #notify_status, #t_enum
Constructor Details
#initialize(user: nil) ⇒ NavbarComponent
Returns a new instance of NavbarComponent.
7 8 9 10 |
# File 'app/components/layout/navbar_component.rb', line 7 def initialize(user: nil) super @user = user end |
Instance Method Details
#admin_submenu ⇒ Array
Returns admin menu entries.
76 77 78 79 80 81 82 83 84 |
# File 'app/components/layout/navbar_component.rb', line 76 def return unless @user.admin? [ link_to(t(".admin.groups"), admin_groups_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"), link_to(t(".admin.users"), admin_users_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"), link_to(t(".admin.templates"), admin_templates_path, data: { turbo: { frame: "yield" } }, class: "navbar-item") ] end |
#call ⇒ String
Generate an html safe string with full ispra top menu
14 15 16 |
# File 'app/components/layout/navbar_component.rb', line 14 def call tag.div tag.div(, class: "container"), id: "nav3" end |
#editor_submenu ⇒ Array
Returns admin menu entries.
87 88 89 90 91 92 93 94 95 |
# File 'app/components/layout/navbar_component.rb', line 87 def return unless @user.editor? [ link_to(t(".editor.events"), editor_events_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"), link_to(t(".editor.happenings"), editor_happenings_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"), link_to(t(".editor.users"), editor_users_path, data: { turbo: { frame: "yield" } }, class: "navbar-item") ] end |
#lang_submenu ⇒ Object
Generate the ‘select language’ submenu html block
50 51 52 53 54 55 56 |
# File 'app/components/layout/navbar_component.rb', line 50 def title = icon("fas fa-globe") sub = link_to("IT", events_path(locale: "it"), class: "navbar-item") + link_to("EN", events_path(locale: "en"), class: "navbar-item") title:, sub: # tag.div lang_title + lang_dropdown, class: 'navbar-item has-dropdown is-hoverable has-background-primary-dark' end |
#navbar ⇒ Object
render Bulmacomp::NavbarComponent with the options
19 20 21 |
# File 'app/components/layout/navbar_component.rb', line 19 def render Bulmacomp::NavbarComponent.new(brand: , navbar_start:, navbar_end:) end |
#navbar_end ⇒ Object
Generate the navbar-end html block
39 40 41 42 43 44 45 46 47 |
# File 'app/components/layout/navbar_component.rb', line 39 def ret = [ ] if @user.present? ret << else ret << link_to(icon_text("fas fa-right-to-bracket", t(".sign_in")), new_user_session_path, data: { turbo_frame: "yield" }, class: "navbar-item") end safe_join(ret) end |
#navbar_start ⇒ Object
Gerate the navbar-start html block
30 31 32 33 34 35 36 |
# File 'app/components/layout/navbar_component.rb', line 30 def safe_join [ link_to(icon_text("fas fa-calendar", t(".events")), events_path, data: { turbo_frame: "yield" }, class: "navbar-item"), link_to(icon_text("fas fa-calendar-day", t(".happenings")), happenings_path, data: { turbo_frame: "yield" }, class: "navbar-item"), link_to(icon_text("fas fa-ticket-alt", t(".tickets")), tickets_path, data: { turbo_frame: "yield" }, class: "navbar-item") ] end |
#navbar_title ⇒ Object
Generate the navbar-title html block
24 25 26 27 |
# File 'app/components/layout/navbar_component.rb', line 24 def title = ENV.fetch("RAILS_TITLE", "Partecipo") safe_join([ icon(ENV.fetch("RAILS_ICON", "fas fa-signature")), tag.span(title.first), title[1..] ]) end |
#submenu(title:, sub:) ⇒ Object
58 59 60 61 |
# File 'app/components/layout/navbar_component.rb', line 58 def (title:, sub:) style = "navbar-item has-dropdown is-hoverable" tag.div link_to(title, "", class: "navbar-link") + tag.div(sub, class: "navbar-dropdown"), class: style end |
#user_submenu ⇒ Object
Generate the user submenu html block
64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/layout/navbar_component.rb', line 64 def title = icon_text("fas fa-user", @user.email) sub = safe_join([ , , (link_to(t(".user_edit"), edit_user_registration_path, class: "navbar-item") if RAILS_DEVISE_DATABASE_AUTHENTICATABLE), link_to(t(".sign_out"), destroy_user_session_path, data: { turbo_method: :delete }, class: "navbar-item") ]) title:, sub: end |