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 ⇒ Object
-
#call ⇒ String
Generate an html safe string with full ispra top menu.
- #editor_submenu ⇒ Object
-
#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.
11 12 13 14 |
# File 'app/components/layout/navbar_component.rb', line 11 def initialize(user: nil) super @user = user end |
Instance Method Details
#admin_submenu ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/components/layout/navbar_component.rb', line 84 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") ] end |
#call ⇒ String
Generate an html safe string with full ispra top menu
18 19 20 |
# File 'app/components/layout/navbar_component.rb', line 18 def call tag.div tag.div(, class: "container"), id: "nav3", class: "has-background-primary-dark" end |
#editor_submenu ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'app/components/layout/navbar_component.rb', line 94 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
57 58 59 60 61 62 63 |
# File 'app/components/layout/navbar_component.rb', line 57 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
23 24 25 26 |
# File 'app/components/layout/navbar_component.rb', line 23 def render Bulmacomp::NavbarComponent.new(brand: , navbar_start:, navbar_end:, class: "navbar has-background-primary-dark") end |
#navbar_end ⇒ Object
Generate the navbar-end html block
45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/layout/navbar_component.rb', line 45 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: false }, class: "navbar-item") end safe_join(ret) end |
#navbar_start ⇒ Object
Gerate the navbar-start html block
34 35 36 37 38 39 40 41 42 |
# File 'app/components/layout/navbar_component.rb', line 34 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, class: "navbar-item") ] end |
#navbar_title ⇒ Object
Generate the navbar-title html block
29 30 31 |
# File 'app/components/layout/navbar_component.rb', line 29 def safe_join([ icon_text("fas fa-signature", "P"), "artecipo" ]) end |
#submenu(title:, sub:) ⇒ Object
65 66 67 68 |
# File 'app/components/layout/navbar_component.rb', line 65 def (title:, sub:) style = "navbar-item has-dropdown is-hoverable has-background-primary-dark" 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
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/components/layout/navbar_component.rb', line 71 def title = icon_text("fas fa-user", @user.email) sub = safe_join([ , , link_to(t(".user_edit"), edit_user_registration_path, class: "navbar-item"), link_to(t(".sign_out"), destroy_user_session_path, data: { turbo_method: :delete }, class: "navbar-item") ]) title:, sub: end |