bootstrap-navbar 3.0.7 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31c1c11b16764f02d05e907c90ec1485dc0ca435032b1492d873f3d79c3818c6
4
- data.tar.gz: 1e8dfe8093cc0455703c9ce05eb80590ade4bcb93f8b01fc53d8fd7f3b41595d
3
+ metadata.gz: 5ccbc5a37579d9b5af476053a83aa4afcb9fde6f440d434a625a1417ded422d3
4
+ data.tar.gz: c65fee68a97969d1b79250ed8a5d91a3ce8f75fe3ab54587d0d45620f125b90b
5
5
  SHA512:
6
- metadata.gz: 1f5b2f052f44d4c98533712ed45e6fe323c1d15a6f041d7e1a67cb8590122bc12cbbc9b4564995da40280c194b58500855609257be197f08928013547b011064
7
- data.tar.gz: 65ceeca8fe2f44d3ca81fecc926876936bf7b1907adbd35061befddea130d7d4593e8a8726b0d3e79701c21c64d8320792c419465e83a5b31013a97c9fca5e9a
6
+ metadata.gz: 4d7d31ee966cc6d4e38be6ac10bd30487f546f5ffb4ce98692f87882e00edd95477104e301cea43f95821d2d82414930ed9416349e81bb66868983d30e3fc266
7
+ data.tar.gz: ca5b478631da2d7545688a8c2a5c78b0061bd3de6d3ca14c9a60bcef4a62b2babfe9c1ac9a56e5e20a85e7d92ff28ba0612cde82db5e284c49c109a24ed4ee5b
@@ -3,10 +3,14 @@ module BootstrapNavbar::Helpers::Bootstrap4
3
3
  options = options.dup
4
4
  container = options.key?(:container) ? options.delete(:container) : false
5
5
  brand = if options[:brand]
6
+ brand_url = options.delete(:brand_url)
7
+ element, attributes = brand_url == false ? ['span', {}] : ['a', { href: brand_url || '/' }]
8
+ attributes[:class] = 'navbar-brand'
9
+
6
10
  prepare_html <<~HTML
7
- <a href="#{options.delete(:brand_url) || '/'}" class="navbar-brand">
11
+ <#{element}#{attributes_for_tag(attributes)}>
8
12
  #{options.delete(:brand)}
9
- </a>
13
+ </#{element}>
10
14
  HTML
11
15
  end
12
16
  wrapper options do
@@ -62,8 +66,12 @@ module BootstrapNavbar::Helpers::Bootstrap4
62
66
  HTML
63
67
  end
64
68
 
69
+ def navbar_text(text)
70
+ %(<span class="navbar-text">#{text}</span>)
71
+ end
72
+
65
73
  def navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block)
66
- text, url, list_item_options, link_options = capture(&block), text, url, list_item_options if block_given?
74
+ text, url, list_item_options, link_options = capture(&block), text, (url || {}), list_item_options if block_given?
67
75
  url ||= '#'
68
76
  list_item_options = list_item_options ? list_item_options.dup : {}
69
77
  link_options = link_options ? link_options.dup : {}
@@ -82,25 +90,30 @@ module BootstrapNavbar::Helpers::Bootstrap4
82
90
  HTML
83
91
  end
84
92
 
85
- def navbar_dropdown(text, id = '', list_item_options = {}, link_options = {}, &block)
93
+ def navbar_dropdown(text, list_item_options = {}, link_options = {}, wrapper_options = {}, &block)
86
94
  list_item_options, link_options = list_item_options.dup, link_options.dup
87
95
  list_item_options[:class] = [list_item_options[:class], 'nav-item', 'dropdown'].compact.join(' ')
88
- wrapper_class = [*list_item_options.delete(:wrapper_class), 'dropdown-menu'].compact.join(' ')
89
96
  list_item_attributes = attributes_for_tag(list_item_options)
90
97
  link_options[:class] = [link_options[:class], 'nav-link', 'dropdown-toggle'].compact.join(' ')
91
- id ||= "navbarDropdownMenuLink#{text}"
92
98
  link_attributes = attributes_for_tag(link_options)
99
+ wrapper_options = { class: [*wrapper_options.delete(:class), 'dropdown-menu'].compact.join(' ') }
100
+ if id = link_options[:id]
101
+ wrapper_options[:'aria-labelledby'] = id
102
+ end
103
+ wrapper_attributes = attributes_for_tag(wrapper_options)
93
104
  prepare_html <<~HTML
94
105
  <li#{list_item_attributes}>
95
- <a href="#" data-toggle="dropdown" id="##{id}" aria-haspopup="true" aria-expanded="false" role="button" #{link_attributes}>#{text}</a>
96
- <div class="#{wrapper_class}" aria-labelledby="#{id}">
106
+ <a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"#{link_attributes}>#{text}</a>
107
+ <div#{wrapper_attributes}>
97
108
  #{capture(&block) if block_given?}
98
109
  </div>
99
110
  </li>
100
111
  HTML
101
112
  end
102
113
 
103
- def navbar_dropdown_item(text, url = '#', link_options = {}, &block)
114
+ def navbar_dropdown_item(text, url = nil, link_options = {}, &block)
115
+ text, url, link_options = capture(&block), text, (url || {}) if block_given?
116
+ url ||= '#'
104
117
  link_options = link_options.dup
105
118
  link_options[:class] = [link_options[:class], 'dropdown-item'].compact
106
119
  link_options[:class] << 'active' if current_url_or_sub_url?(url)
@@ -144,7 +157,10 @@ module BootstrapNavbar::Helpers::Bootstrap4
144
157
  elsif options.key?(:placement)
145
158
  options[:class] << "fixed-#{options.delete(:placement)}"
146
159
  end
147
- options[:class] << "navbar-expand-#{options.delete(:expand_at) || 'sm'}"
160
+ expand_at = options.delete(:expand_at)
161
+ unless expand_at == true
162
+ options[:class] << "navbar-expand#{"-#{expand_at}" if expand_at}"
163
+ end
148
164
  options[:class] = options[:class].join(' ')
149
165
  attributes = attributes_for_tag(options)
150
166
  prepare_html <<~HTML
@@ -0,0 +1,169 @@
1
+ module BootstrapNavbar::Helpers::Bootstrap5
2
+ def navbar(options = {}, &block)
3
+ options = options.dup
4
+ unless container = options.key?(:container) ? options.delete(:container) : true
5
+ raise "container cannot be false."
6
+ end
7
+ brand = if options[:brand]
8
+ brand_url = options.delete(:brand_url)
9
+ element, attributes = brand_url == false ? ['span', {}] : ['a', { href: brand_url || '/' }]
10
+ attributes[:class] = 'navbar-brand'
11
+
12
+ prepare_html <<~HTML
13
+ <#{element}#{attributes_for_tag(attributes)}>
14
+ #{options.delete(:brand)}
15
+ </#{element}>
16
+ HTML
17
+ end
18
+ wrapper options do
19
+ container container do
20
+ prepare_html <<~HTML
21
+ #{brand}
22
+ #{capture(&block) if block_given?}
23
+ HTML
24
+ end
25
+ end
26
+ end
27
+
28
+ def navbar_collapse(options = {}, &block)
29
+ options = options.dup
30
+ options[:class] = [options[:class], 'collapse', 'navbar-collapse'].compact
31
+ options[:class] = options[:class].join(' ')
32
+ options[:id] ||= 'navbar-collapsable'
33
+ attributes = attributes_for_tag(options)
34
+ toggler_attributes = attributes_for_tag(
35
+ class: 'navbar-toggler',
36
+ type: 'button',
37
+ 'data-bs-toggle' => 'collapse',
38
+ 'data-bs-target' => "##{options[:id]}",
39
+ 'aria-controls' => options[:id],
40
+ 'aria-expanded' => false,
41
+ 'aria-label' => 'Toggle navigation'
42
+ )
43
+ prepare_html <<~HTML
44
+ <button#{toggler_attributes}>
45
+ <span class="navbar-toggler-icon"></span>
46
+ </button>
47
+ <div#{attributes}>
48
+ #{capture(&block) if block_given?}
49
+ </div>
50
+ HTML
51
+ end
52
+
53
+ def navbar_group(options = {}, &block)
54
+ options = options.dup
55
+ options[:class] = [options[:class], 'navbar-nav'].compact.join(' ')
56
+ attributes = attributes_for_tag(options)
57
+ prepare_html <<~HTML
58
+ <ul#{attributes}>
59
+ #{capture(&block) if block_given?}
60
+ </ul>
61
+ HTML
62
+ end
63
+
64
+ def navbar_text(text)
65
+ %(<span class="navbar-text">#{text}</span>)
66
+ end
67
+
68
+ def navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block)
69
+ text, url, list_item_options, link_options = capture(&block), text, (url || {}), list_item_options if block_given?
70
+ url ||= '#'
71
+ list_item_options = list_item_options ? list_item_options.dup : {}
72
+ link_options = link_options ? link_options.dup : {}
73
+ list_item_options[:class] = [list_item_options[:class], 'nav-item'].compact.join(' ')
74
+ link_options[:class] = [link_options[:class], 'nav-link'].compact
75
+ link_options[:class] << 'active' if current_url_or_sub_url?(url)
76
+ link_options[:class] = link_options[:class].join(' ')
77
+ list_item_attributes = attributes_for_tag(list_item_options)
78
+ link_attributes = attributes_for_tag(link_options)
79
+ prepare_html <<~HTML
80
+ <li#{list_item_attributes}>
81
+ <a href="#{url}"#{link_attributes}>
82
+ #{text}
83
+ </a>
84
+ </li>
85
+ HTML
86
+ end
87
+
88
+ def navbar_dropdown(text, list_item_options = {}, link_options = {}, wrapper_options = {}, &block)
89
+ list_item_options, link_options = list_item_options.dup, link_options.dup
90
+ list_item_options[:class] = [list_item_options[:class], 'nav-item', 'dropdown'].compact.join(' ')
91
+ list_item_attributes = attributes_for_tag(list_item_options)
92
+ link_options[:class] = [link_options[:class], 'nav-link', 'dropdown-toggle'].compact.join(' ')
93
+ link_attributes = attributes_for_tag(link_options)
94
+ wrapper_options = { class: [*wrapper_options.delete(:class), 'dropdown-menu'].compact.join(' ') }
95
+ if id = link_options[:id]
96
+ wrapper_options[:'aria-labelledby'] = id
97
+ end
98
+ wrapper_attributes = attributes_for_tag(wrapper_options)
99
+ prepare_html <<~HTML
100
+ <li#{list_item_attributes}>
101
+ <a href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"#{link_attributes}>#{text}</a>
102
+ <ul#{wrapper_attributes}>
103
+ #{capture(&block) if block_given?}
104
+ </div>
105
+ </li>
106
+ HTML
107
+ end
108
+
109
+ def navbar_dropdown_item(text, url = nil, link_options = {}, &block)
110
+ text, url, link_options = capture(&block), text, (url || {}) if block_given?
111
+ url ||= '#'
112
+ link_options = link_options.dup
113
+ link_options[:class] = [link_options[:class], 'dropdown-item'].compact
114
+ link_options[:class] << 'active' if current_url_or_sub_url?(url)
115
+ link_options[:class] = link_options[:class].join(' ')
116
+ link_attributes = attributes_for_tag(link_options)
117
+ prepare_html <<~HTML
118
+ <li>
119
+ <a href="#{url}"#{link_attributes}>
120
+ #{text}
121
+ </a>
122
+ </li>
123
+ HTML
124
+ end
125
+
126
+ def navbar_dropdown_divider
127
+ '<div class="dropdown-divider"></div>'
128
+ end
129
+
130
+ private
131
+
132
+ def container(container, &block)
133
+ container_class = [
134
+ 'container',
135
+ (container unless container == true)
136
+ ].compact.join('-')
137
+ attributes = attributes_for_tag(class: container_class)
138
+ prepare_html <<~HTML
139
+ <div#{attributes}>
140
+ #{capture(&block) if block_given?}
141
+ </div>
142
+ HTML
143
+ end
144
+
145
+ def wrapper(options, &block)
146
+ options = options.dup
147
+ options[:class] = [options[:class], 'navbar'].compact
148
+ options[:class] << "navbar-#{options.key?(:color_scheme) ? options.delete(:color_scheme) : 'dark'}"
149
+ if bg = options.delete(:bg)
150
+ options[:class] << "bg-#{bg == true ? 'dark' : bg}"
151
+ end
152
+ if options.key?(:sticky) && options.delete(:sticky) === true
153
+ options[:class] << 'sticky-top'
154
+ elsif options.key?(:placement)
155
+ options[:class] << "fixed-#{options.delete(:placement)}"
156
+ end
157
+ expand_at = options.delete(:expand_at)
158
+ unless expand_at == true
159
+ options[:class] << "navbar-expand#{"-#{expand_at}" if expand_at}"
160
+ end
161
+ options[:class] = options[:class].join(' ')
162
+ attributes = attributes_for_tag(options)
163
+ prepare_html <<~HTML
164
+ <nav#{attributes}>
165
+ #{capture(&block) if block_given?}
166
+ </nav>
167
+ HTML
168
+ end
169
+ end
@@ -1,3 +1,3 @@
1
1
  module BootstrapNavbar
2
- VERSION = '3.0.7'
2
+ VERSION = '3.2.0'
3
3
  end
@@ -15,3 +15,4 @@ require_relative 'bootstrap-navbar/helpers'
15
15
  require_relative 'bootstrap-navbar/helpers/bootstrap2'
16
16
  require_relative 'bootstrap-navbar/helpers/bootstrap3'
17
17
  require_relative 'bootstrap-navbar/helpers/bootstrap4'
18
+ require_relative 'bootstrap-navbar/helpers/bootstrap5'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-navbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -142,6 +142,7 @@ files:
142
142
  - lib/bootstrap-navbar/helpers/bootstrap2.rb
143
143
  - lib/bootstrap-navbar/helpers/bootstrap3.rb
144
144
  - lib/bootstrap-navbar/helpers/bootstrap4.rb
145
+ - lib/bootstrap-navbar/helpers/bootstrap5.rb
145
146
  - lib/bootstrap-navbar/version.rb
146
147
  - spec/bootstrap-navbar/helpers/bootstrap2_spec.rb
147
148
  - spec/bootstrap-navbar/helpers/bootstrap3_spec.rb
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  - !ruby/object:Gem::Version
169
170
  version: '0'
170
171
  requirements: []
171
- rubygems_version: 3.1.3
172
+ rubygems_version: 3.2.30
172
173
  signing_key:
173
174
  specification_version: 4
174
175
  summary: Helpers to generate a Bootstrap style navbar