Module: BootstrapNavbar::Helpers::Bootstrap5
- Defined in:
- lib/bootstrap-navbar/helpers/bootstrap5.rb
Instance Method Summary collapse
- #navbar(options = {}, &block) ⇒ Object
- #navbar_collapse(options = {}, &block) ⇒ Object
- #navbar_dropdown(text, list_item_options = {}, link_options = {}, wrapper_options = {}, &block) ⇒ Object
- #navbar_dropdown_divider ⇒ Object
- #navbar_dropdown_item(text, url = nil, link_options = {}, &block) ⇒ Object
- #navbar_group(options = {}, &block) ⇒ Object
- #navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block) ⇒ Object
- #navbar_text(text) ⇒ Object
Instance Method Details
#navbar(options = {}, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 2 def ( = {}, &block) = .dup unless container = .key?(:container) ? .delete(:container) : true raise "container cannot be false." end brand = if [:brand] brand_url = .delete(:brand_url) element, attributes = brand_url == false ? ['span', {}] : ['a', { href: brand_url || '/' }] attributes[:class] = 'navbar-brand' prepare_html <<~HTML <#{element}#{attributes_for_tag(attributes)}> #{.delete(:brand)} </#{element}> HTML end wrapper do container container do prepare_html <<~HTML #{brand} #{capture(&block) if block_given?} HTML end end end |
#navbar_collapse(options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 28 def ( = {}, &block) = .dup [:class] = [[:class], 'collapse', 'navbar-collapse'].compact [:class] = [:class].join(' ') [:id] ||= 'navbar-collapsable' attributes = attributes_for_tag() toggler_attributes = attributes_for_tag( class: 'navbar-toggler', type: 'button', 'data-bs-toggle' => 'collapse', 'data-bs-target' => "##{[:id]}", 'aria-controls' => [:id], 'aria-expanded' => false, 'aria-label' => 'Toggle navigation' ) prepare_html <<~HTML <button#{toggler_attributes}> <span class="navbar-toggler-icon"></span> </button> <div#{attributes}> #{capture(&block) if block_given?} </div> HTML end |
#navbar_dropdown(text, list_item_options = {}, link_options = {}, wrapper_options = {}, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 88 def (text, = {}, = {}, = {}, &block) , = .dup, .dup [:class] = [[:class], 'nav-item', 'dropdown'].compact.join(' ') list_item_attributes = attributes_for_tag() [:class] = [[:class], 'nav-link', 'dropdown-toggle'].compact.join(' ') link_attributes = attributes_for_tag() = { class: [*.delete(:class), 'dropdown-menu'].compact.join(' ') } if id = [:id] [:'aria-labelledby'] = id end wrapper_attributes = attributes_for_tag() prepare_html <<~HTML <li#{list_item_attributes}> <a href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"#{link_attributes}>#{text}</a> <ul#{wrapper_attributes}> #{capture(&block) if block_given?} </ul> </li> HTML end |
#navbar_dropdown_divider ⇒ Object
126 127 128 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 126 def '<div class="dropdown-divider"></div>' end |
#navbar_dropdown_item(text, url = nil, link_options = {}, &block) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 109 def (text, url = nil, = {}, &block) text, url, = capture(&block), text, (url || {}) if block_given? url ||= '#' = .dup [:class] = [[:class], 'dropdown-item'].compact [:class] << 'active' if current_url_or_sub_url?(url) [:class] = [:class].join(' ') link_attributes = attributes_for_tag() prepare_html <<~HTML <li> <a href="#{url}"#{link_attributes}> #{text} </a> </li> HTML end |
#navbar_group(options = {}, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 53 def ( = {}, &block) = .dup [:class] = [[:class], 'navbar-nav'].compact.join(' ') attributes = attributes_for_tag() prepare_html <<~HTML <ul#{attributes}> #{capture(&block) if block_given?} </ul> HTML end |
#navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 68 def (text, url = nil, = nil, = nil, &block) text, url, , = capture(&block), text, (url || {}), if block_given? url ||= '#' = ? .dup : {} = ? .dup : {} [:class] = [[:class], 'nav-item'].compact.join(' ') [:class] = [[:class], 'nav-link'].compact [:class] << 'active' if current_url_or_sub_url?(url) [:class] = [:class].join(' ') list_item_attributes = attributes_for_tag() link_attributes = attributes_for_tag() prepare_html <<~HTML <li#{list_item_attributes}> <a href="#{url}"#{link_attributes}> #{text} </a> </li> HTML end |
#navbar_text(text) ⇒ Object
64 65 66 |
# File 'lib/bootstrap-navbar/helpers/bootstrap5.rb', line 64 def (text) %(<span class="navbar-text">#{text}</span>) end |