Class: NfgUi::Bootstrap::Components::NavItem

Inherits:
Base
  • Object
show all
Includes:
Utilities::Wrappable
Defined in:
lib/nfg_ui/bootstrap/components/nav_item.rb

Overview

Direct Known Subclasses

Components::Elements::NavItem

Instance Attribute Summary

Attributes included from Utilities::Wrappable

#as

Attributes inherited from Base

#body, #options, #view_context

Instance Method Summary collapse

Methods included from Utilities::Wrappable

#utility_initialize

Methods inherited from Base

#data, #href, #id, #initialize, #style

Constructor Details

This class inherits a constructor from NfgUi::Bootstrap::Components::Base

Instance Method Details

#activeObject

For passing through to nav_link bypass module since active / disabled is applied on the nav_link



14
15
16
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 14

def active
  options.fetch(:active, false)
end

#buttonObject



18
19
20
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 18

def button
  options.fetch(:button, nil)
end

#component_familyObject



22
23
24
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 22

def component_family
  :nav
end

#disabledObject

For passing through to nav_link



31
32
33
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 31

def disabled
  options.fetch(:disabled, false)
end


35
36
37
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 35

def dropdown
  options.fetch(:dropdown, false)
end

#html_optionsObject

href gets passed to the nav_link when present. Removes :href from nav_item’s html_options so we don’t end up with <li class=‘nav-item’ href=‘#href’><a class=‘nav-link’ href=‘#href’…



50
51
52
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 50

def html_options
  super.except!(:href)
end

#include_nav_link?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 39

def include_nav_link?
  href.present? || dropdown || tab
end

#remoteObject



26
27
28
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 26

def remote
  options.fetch(:remote, nil)
end

#renderObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 54

def render
  super do
    capture do
      if include_nav_link?
        concat(NfgUi::Bootstrap::Components::NavLink.new({ body: (button ? button : (block_given? ? yield : body)), active: active, disabled: disabled, dropdown: dropdown, tab: tab, remote: remote, href: (tab || href) }, view_context).render)
        concat(block_given? ? yield : body) if dropdown
      else
        (block_given? ? yield : body)
      end
    end
  end
end

#tabObject



43
44
45
# File 'lib/nfg_ui/bootstrap/components/nav_item.rb', line 43

def tab
  options.fetch(:tab, nil)
end