Skip to content

Commit dd422f4

Browse files
author
Mattia Roccoberton
committed
feat: improve navbar component
1 parent b3202d3 commit dd422f4

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

lib/tiny_admin/settings.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def load_settings
4040

4141
@root ||= {}
4242
@root[:title] ||= 'TinyAdmin'
43-
@root[:path] ||= root_path
4443
@root[:page] ||= Views::Pages::Root
4544

4645
if @authentication[:plugin] == Plugins::SimpleAuth

lib/tiny_admin/views/components/navbar.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ module TinyAdmin
44
module Views
55
module Components
66
class Navbar < Phlex::HTML
7-
attr_reader :current_slug, :items, :root
7+
attr_reader :current_slug, :items, :root_path, :root_title
88

9-
def initialize(root:, items: [], current_slug: nil)
10-
@root = root
9+
def initialize(root_path:, root_title:, items: [], current_slug: nil)
10+
@root_path = root_path
11+
@root_title = root_title
1112
@items = items || []
1213
@current_slug = current_slug
1314
end
1415

1516
def template
1617
nav(class: 'navbar navbar-expand-lg') {
1718
div(class: 'container') {
18-
a(class: 'navbar-brand', href: root[:path]) { root[:title] }
19+
a(class: 'navbar-brand', href: root_path) { root_title }
1920
button(class: 'navbar-toggler', type: 'button', 'data-bs-toggle' => 'collapse', 'data-bs-target' => '#navbarNav', 'aria-controls' => 'navbarNav', 'aria-expanded' => 'false', 'aria-label' => 'Toggle navigation') {
2021
span(class: 'navbar-toggler-icon')
2122
}

lib/tiny_admin/views/default_layout.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ def template(&block)
1111
render components[:head].new(title, style_links: style_links, extra_styles: settings.extra_styles)
1212

1313
body(class: body_class) {
14-
render components[:navbar].new(current_slug: context&.slug, root: settings.root, items: navbar_items)
14+
navbar_attrs = {
15+
current_slug: context&.slug,
16+
root_path: settings.root_path,
17+
root_title: settings.root[:title],
18+
items: navbar_items
19+
}
20+
render components[:navbar].new(**navbar_attrs)
1521

1622
main_content {
1723
render components[:flash].new(messages: messages || {})

0 commit comments

Comments
 (0)