Class: TinyAdmin::Views::Components::Navbar

Inherits:
BasicComponent
  • Object
show all
Defined in:
lib/tiny_admin/views/components/navbar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicComponent

#update_attributes

Instance Attribute Details

#current_slugObject

Returns the value of attribute current_slug.



7
8
9
# File 'lib/tiny_admin/views/components/navbar.rb', line 7

def current_slug
  @current_slug
end

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/tiny_admin/views/components/navbar.rb', line 7

def items
  @items
end

#root_pathObject

Returns the value of attribute root_path.



7
8
9
# File 'lib/tiny_admin/views/components/navbar.rb', line 7

def root_path
  @root_path
end

#root_titleObject

Returns the value of attribute root_title.



7
8
9
# File 'lib/tiny_admin/views/components/navbar.rb', line 7

def root_title
  @root_title
end

Instance Method Details

#view_templateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tiny_admin/views/components/navbar.rb', line 9

def view_template
  nav(class: 'navbar navbar-expand-lg') {
    div(class: 'container') {
      a(class: 'navbar-brand', href: root_path) { root_title }
      button(
        class: 'navbar-toggler',
        type: 'button',
        'data-bs-toggle' => 'collapse',
        'data-bs-target' => '#navbarNav',
        'aria-controls' => 'navbarNav',
        'aria-expanded' => 'false',
        'aria-label' => 'Toggle navigation'
      ) {
        span(class: 'navbar-toggler-icon')
      }
      div(class: 'collapse navbar-collapse', id: 'navbarNav') {
        ul(class: 'navbar-nav') {
          items.each do |item|
            classes = %w[nav-link]
            classes << 'active' if item.slug == current_slug
            link_attributes = { class: classes.join(' '), href: item.path, 'aria-current' => 'page' }
            link_attributes.merge!(item.options) if item.options

            li(class: 'nav-item') {
              a(**link_attributes) { item.name }
            }
          end
        }
      }
    }
  }
end