bootstrap-navbar 3.0.3 → 3.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c052de755ae4a79228172a5542806fcbc43b938203d6d9791d210543bb14d72
|
4
|
+
data.tar.gz: 46311e56c6a5e5dc824db02ca9377c8c1798d046807103aaf7428960b696b3bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14629006361ae67397f55ba652a84845ba4ef1ae505a52c29f3c7486b19e078e8d796453cb880921b393dbe157e80ac7020438e040d49222bc363d13cafb04c6
|
7
|
+
data.tar.gz: 61cdb5083e9b9421df76db12078d3ef12faf735fe53ecafd3fdfaece19502a040314ae6615d0f390e77a715431198ac42a926260e7e1d7f46f4d3415994e723e
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/bootstrap-navbar)
|
4
4
|
[](http://travis-ci.org/bootstrap-ruby/bootstrap-navbar)
|
5
|
-
[](https://gemnasium.com/bootstrap-ruby/bootstrap-navbar)
|
6
5
|
[](https://codeclimate.com/github/bootstrap-ruby/bootstrap-navbar)
|
7
6
|
|
8
7
|
Helpers to generate a Bootstrap style navbar
|
@@ -103,3 +102,7 @@ See [CHANGELOG](CHANGELOG.md)
|
|
103
102
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
104
103
|
4. Push to the branch (`git push origin my-new-feature`)
|
105
104
|
5. Create new Pull Request
|
105
|
+
|
106
|
+
## Support
|
107
|
+
|
108
|
+
If you like this project, consider [buying me a coffee](https://www.buymeacoffee.com/279lcDtbF)! :)
|
@@ -15,14 +15,14 @@ module BootstrapNavbar::Helpers
|
|
15
15
|
def attributes_for_tag(hash)
|
16
16
|
string = hash.map { |k, v| %(#{k}="#{v}") }.join(' ')
|
17
17
|
if string.length > 0
|
18
|
-
' ' << string
|
18
|
+
' '.dup << string
|
19
19
|
else
|
20
20
|
string
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def current_url_or_sub_url?(url)
|
25
|
-
return false if url == '#'
|
25
|
+
return false if url == '#' || url =~ /\Atel:/
|
26
26
|
uri, current_uri = [url, current_url].map do |url|
|
27
27
|
URI.parse(url)
|
28
28
|
end
|
@@ -2,11 +2,26 @@ module BootstrapNavbar::Helpers::Bootstrap4
|
|
2
2
|
def navbar(options = {}, &block)
|
3
3
|
options = options.dup
|
4
4
|
container = options.key?(:container) ? options.delete(:container) : false
|
5
|
+
brand = if options[:brand]
|
6
|
+
prepare_html <<~HTML
|
7
|
+
<a href="#{options.delete(:brand_url) || '/'}" class="navbar-brand">
|
8
|
+
#{options.delete(:brand)}
|
9
|
+
</a>
|
10
|
+
HTML
|
11
|
+
end
|
5
12
|
wrapper options do
|
6
13
|
if container
|
7
|
-
container
|
14
|
+
container container do
|
15
|
+
prepare_html <<~HTML
|
16
|
+
#{brand}
|
17
|
+
#{capture(&block) if block_given?}
|
18
|
+
HTML
|
19
|
+
end
|
8
20
|
else
|
9
|
-
|
21
|
+
prepare_html <<~HTML
|
22
|
+
#{brand}
|
23
|
+
#{capture(&block) if block_given?}
|
24
|
+
HTML
|
10
25
|
end
|
11
26
|
end
|
12
27
|
end
|
@@ -26,29 +41,29 @@ module BootstrapNavbar::Helpers::Bootstrap4
|
|
26
41
|
'aria-expanded' => false,
|
27
42
|
'aria-label' => 'Toggle navigation'
|
28
43
|
)
|
29
|
-
prepare_html
|
30
|
-
<button#{toggler_attributes}>
|
31
|
-
|
32
|
-
</button>
|
33
|
-
<div#{attributes}>
|
34
|
-
|
35
|
-
</div>
|
36
|
-
HTML
|
44
|
+
prepare_html <<~HTML
|
45
|
+
<button#{toggler_attributes}>
|
46
|
+
<span class="navbar-toggler-icon"></span>
|
47
|
+
</button>
|
48
|
+
<div#{attributes}>
|
49
|
+
#{capture(&block) if block_given?}
|
50
|
+
</div>
|
51
|
+
HTML
|
37
52
|
end
|
38
53
|
|
39
54
|
def navbar_group(options = {}, &block)
|
40
55
|
options = options.dup
|
41
56
|
options[:class] = [options[:class], 'navbar-nav'].compact.join(' ')
|
42
57
|
attributes = attributes_for_tag(options)
|
43
|
-
prepare_html
|
44
|
-
<ul#{attributes}>
|
45
|
-
|
46
|
-
</ul>
|
47
|
-
HTML
|
58
|
+
prepare_html <<~HTML
|
59
|
+
<ul#{attributes}>
|
60
|
+
#{capture(&block) if block_given?}
|
61
|
+
</ul>
|
62
|
+
HTML
|
48
63
|
end
|
49
64
|
|
50
65
|
def navbar_item(text, url = nil, list_item_options = nil, link_options = nil, &block)
|
51
|
-
text, url, list_item_options, link_options = capture(&block), text, url, list_item_options if block_given?
|
66
|
+
text, url, list_item_options, link_options = capture(&block), text, (url || {}), list_item_options if block_given?
|
52
67
|
url ||= '#'
|
53
68
|
list_item_options = list_item_options ? list_item_options.dup : {}
|
54
69
|
link_options = link_options ? link_options.dup : {}
|
@@ -58,88 +73,92 @@ HTML
|
|
58
73
|
link_options[:class] = link_options[:class].join(' ')
|
59
74
|
list_item_attributes = attributes_for_tag(list_item_options)
|
60
75
|
link_attributes = attributes_for_tag(link_options)
|
61
|
-
prepare_html
|
62
|
-
<li#{list_item_attributes}>
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</li>
|
67
|
-
HTML
|
76
|
+
prepare_html <<~HTML
|
77
|
+
<li#{list_item_attributes}>
|
78
|
+
<a href="#{url}"#{link_attributes}>
|
79
|
+
#{text}
|
80
|
+
</a>
|
81
|
+
</li>
|
82
|
+
HTML
|
68
83
|
end
|
69
84
|
|
70
|
-
def navbar_dropdown(text,
|
85
|
+
def navbar_dropdown(text, list_item_options = {}, link_options = {}, wrapper_options = {}, &block)
|
71
86
|
list_item_options, link_options = list_item_options.dup, link_options.dup
|
72
87
|
list_item_options[:class] = [list_item_options[:class], 'nav-item', 'dropdown'].compact.join(' ')
|
73
88
|
list_item_attributes = attributes_for_tag(list_item_options)
|
74
89
|
link_options[:class] = [link_options[:class], 'nav-link', 'dropdown-toggle'].compact.join(' ')
|
75
|
-
id ||= "navbarDropdownMenuLink#{text}"
|
76
90
|
link_attributes = attributes_for_tag(link_options)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
wrapper_options = { class: [*wrapper_options.delete(:class), 'dropdown-menu'].compact.join(' ') }
|
92
|
+
if id = link_options[:id]
|
93
|
+
wrapper_options[:'aria-labelledby'] = id
|
94
|
+
end
|
95
|
+
wrapper_attributes = attributes_for_tag(wrapper_options)
|
96
|
+
prepare_html <<~HTML
|
97
|
+
<li#{list_item_attributes}>
|
98
|
+
<a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"#{link_attributes}>#{text}</a>
|
99
|
+
<div#{wrapper_attributes}>
|
100
|
+
#{capture(&block) if block_given?}
|
101
|
+
</div>
|
102
|
+
</li>
|
103
|
+
HTML
|
85
104
|
end
|
86
105
|
|
87
|
-
def navbar_dropdown_item(text, url =
|
106
|
+
def navbar_dropdown_item(text, url = nil, link_options = {}, &block)
|
107
|
+
text, url, link_options = capture(&block), text, (url || {}) if block_given?
|
108
|
+
url ||= '#'
|
88
109
|
link_options = link_options.dup
|
89
110
|
link_options[:class] = [link_options[:class], 'dropdown-item'].compact
|
90
111
|
link_options[:class] << 'active' if current_url_or_sub_url?(url)
|
91
112
|
link_options[:class] = link_options[:class].join(' ')
|
92
113
|
link_attributes = attributes_for_tag(link_options)
|
93
|
-
prepare_html
|
94
|
-
<a href="#{url}"#{link_attributes}>
|
95
|
-
|
96
|
-
</a>
|
97
|
-
|
114
|
+
prepare_html <<~HTML
|
115
|
+
<a href="#{url}"#{link_attributes}>
|
116
|
+
#{text}
|
117
|
+
</a>
|
118
|
+
HTML
|
98
119
|
end
|
99
120
|
|
100
121
|
def navbar_dropdown_divider
|
101
|
-
|
102
|
-
<div class="dropdown-divider"></div>
|
103
|
-
HTML
|
122
|
+
'<div class="dropdown-divider"></div>'
|
104
123
|
end
|
105
124
|
|
106
125
|
private
|
107
126
|
|
108
|
-
def container(&block)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
#{text}
|
120
|
-
</a>
|
121
|
-
HTML
|
127
|
+
def container(container, &block)
|
128
|
+
container_class = [
|
129
|
+
'container',
|
130
|
+
(container unless container == true)
|
131
|
+
].compact.join('-')
|
132
|
+
attributes = attributes_for_tag(class: container_class)
|
133
|
+
prepare_html <<~HTML
|
134
|
+
<div#{attributes}>
|
135
|
+
#{capture(&block) if block_given?}
|
136
|
+
</div>
|
137
|
+
HTML
|
122
138
|
end
|
123
139
|
|
124
140
|
def wrapper(options, &block)
|
125
141
|
options = options.dup
|
126
142
|
options[:class] = [options[:class], 'navbar'].compact
|
127
143
|
options[:class] << "navbar-#{options.key?(:color_scheme) ? options.delete(:color_scheme) : 'dark'}"
|
128
|
-
|
144
|
+
if bg = options.delete(:bg)
|
145
|
+
options[:class] << "bg-#{bg == true ? 'dark' : bg}"
|
146
|
+
end
|
129
147
|
if options.key?(:sticky) && options.delete(:sticky) === true
|
130
148
|
options[:class] << 'sticky-top'
|
131
149
|
elsif options.key?(:placement)
|
132
150
|
options[:class] << "fixed-#{options.delete(:placement)}"
|
133
151
|
end
|
134
|
-
|
152
|
+
expand_at = options.delete(:expand_at)
|
153
|
+
unless expand_at == true
|
154
|
+
options[:class] << "navbar-expand#{"-#{expand_at}" if expand_at}"
|
155
|
+
end
|
135
156
|
options[:class] = options[:class].join(' ')
|
136
|
-
brand = brand_link(options.delete(:brand), options.delete(:brand_url)) if options[:brand]
|
137
157
|
attributes = attributes_for_tag(options)
|
138
|
-
prepare_html
|
139
|
-
<nav#{attributes}>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
HTML
|
158
|
+
prepare_html <<~HTML
|
159
|
+
<nav#{attributes}>
|
160
|
+
#{capture(&block) if block_given?}
|
161
|
+
</nav>
|
162
|
+
HTML
|
144
163
|
end
|
145
164
|
end
|
@@ -141,4 +141,22 @@ describe BootstrapNavbar::Helpers::Bootstrap4 do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
144
|
+
|
145
|
+
describe '#navbar_dropdown' do
|
146
|
+
context 'with block' do
|
147
|
+
it 'generates the correct HTML' do
|
148
|
+
expect(renderer.navbar_dropdown('Foo', 'foo') { 'link-text' }).to have_tag(:li, with: { class: 'nav-item dropdown'}) do
|
149
|
+
with_tag :div, with: { class: 'dropdown-menu' }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with right aligned menu' do
|
155
|
+
it 'generates the correct HTML' do
|
156
|
+
expect(renderer.navbar_dropdown('Foo', 'foo', { wrapper_class: 'dropdown-menu-right' }) { 'link-text' }).to have_tag(:li, with: { class: 'nav-item dropdown' }) do
|
157
|
+
with_tag :div, with: { class: 'dropdown-menu dropdown-menu-right' }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
144
162
|
end
|
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
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -153,7 +153,7 @@ homepage: http://bootstrap-ruby.github.io/bootstrap-navbar
|
|
153
153
|
licenses:
|
154
154
|
- MIT
|
155
155
|
metadata: {}
|
156
|
-
post_install_message:
|
156
|
+
post_install_message:
|
157
157
|
rdoc_options: []
|
158
158
|
require_paths:
|
159
159
|
- lib
|
@@ -168,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
|
172
|
-
|
173
|
-
signing_key:
|
171
|
+
rubygems_version: 3.1.3
|
172
|
+
signing_key:
|
174
173
|
specification_version: 4
|
175
174
|
summary: Helpers to generate a Bootstrap style navbar
|
176
175
|
test_files:
|