bootstrap-navbar 3.1.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bootstrap-navbar/helpers/bootstrap5.rb +169 -0
- data/lib/bootstrap-navbar/version.rb +1 -1
- data/lib/bootstrap-navbar.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ccbc5a37579d9b5af476053a83aa4afcb9fde6f440d434a625a1417ded422d3
|
4
|
+
data.tar.gz: c65fee68a97969d1b79250ed8a5d91a3ce8f75fe3ab54587d0d45620f125b90b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d7d31ee966cc6d4e38be6ac10bd30487f546f5ffb4ce98692f87882e00edd95477104e301cea43f95821d2d82414930ed9416349e81bb66868983d30e3fc266
|
7
|
+
data.tar.gz: ca5b478631da2d7545688a8c2a5c78b0061bd3de6d3ca14c9a60bcef4a62b2babfe9c1ac9a56e5e20a85e7d92ff28ba0612cde82db5e284c49c109a24ed4ee5b
|
@@ -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
|
data/lib/bootstrap-navbar.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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
|