Module: BootstrapNavbar::Helpers::Bootstrap4
- Defined in:
- lib/bootstrap-navbar/helpers/bootstrap4.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 27 28 29 30 31 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 2 def ( = {}, &block) = .dup container = .key?(:container) ? .delete(:container) : false 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 if container container container do prepare_html <<~HTML #{brand} #{capture(&block) if block_given?} HTML end else prepare_html <<~HTML #{brand} #{capture(&block) if block_given?} HTML end end end |
#navbar_collapse(options = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 33 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-toggle' => 'collapse', 'data-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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 93 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-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"#{link_attributes}>#{text}</a> <div#{wrapper_attributes}> #{capture(&block) if block_given?} </div> </li> HTML end |
#navbar_dropdown_divider ⇒ Object
129 130 131 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 129 def '<div class="dropdown-divider"></div>' end |
#navbar_dropdown_item(text, url = nil, link_options = {}, &block) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 114 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 <a href="#{url}"#{link_attributes}> #{text} </a> HTML end |
#navbar_group(options = {}, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 58 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 73 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
69 70 71 |
# File 'lib/bootstrap-navbar/helpers/bootstrap4.rb', line 69 def (text) %(<span class="navbar-text">#{text}</span>) end |