bootstrap-navbar 3.0.1 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15b5f788ee43d7dfc722cf75c28e91c2cb363a36f9a58ca6968301eae9977302
4
- data.tar.gz: a2ab4b37f4a2de21dc662ab916849b62aff4ed9dbfea4f04dae19a9206a9464c
3
+ metadata.gz: 503df312703c1b1e21ba7c001b5cb57eb622f265e25c4387459c792375b2202a
4
+ data.tar.gz: 15d6d53635832ca900705bec6363c8823d1e0c17da181bdba4d0e0a507d02b13
5
5
  SHA512:
6
- metadata.gz: 934a989f958b5e39c052e524ebeb49f061f6798bb02957fc464fee322848a918440efc61a6bbea102a728a7102ee784bb1decc8120a9504f58462154abb4eff6
7
- data.tar.gz: 3d0d23275914693b2936406a955f9df128e9964e4e2361bf61c09b28b8bfca9502acd9ce4b3e84ac940f0075c91b271adc3b99f86e2cd5a0087307c96004792e
6
+ metadata.gz: e60999f19b6ed1f441d1886db34118a4c92f98b13856ecddd50061b2dd1445e1e62c3c0f04ffbcf5664df83bc054e0650a8ce21178d0b8b472386dc097f4cb95
7
+ data.tar.gz: b6ae2867cd7d0c87de839fa16676b35917c4500fb9063f8c83532da7e727e2f1a441840b22999978c34c2901d41860d1321c630b5bd0fe1bfc74c3ec50aa418a
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/bootstrap-navbar.png)](http://badge.fury.io/rb/bootstrap-navbar)
4
4
  [![Build Status](https://secure.travis-ci.org/bootstrap-ruby/bootstrap-navbar.png)](http://travis-ci.org/bootstrap-ruby/bootstrap-navbar)
5
- [![Dependency Status](https://gemnasium.com/bootstrap-ruby/bootstrap-navbar.png)](https://gemnasium.com/bootstrap-ruby/bootstrap-navbar)
6
5
  [![Code Climate](https://codeclimate.com/github/bootstrap-ruby/bootstrap-navbar.png)](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(&block)
14
+ container container do
15
+ prepare_html <<~HTML
16
+ #{brand}
17
+ #{capture(&block) if block_given?}
18
+ HTML
19
+ end
8
20
  else
9
- capture(&block) if block_given?
21
+ prepare_html <<~HTML
22
+ #{brand}
23
+ #{capture(&block) if block_given?}
24
+ HTML
10
25
  end
11
26
  end
12
27
  end
@@ -26,25 +41,25 @@ module BootstrapNavbar::Helpers::Bootstrap4
26
41
  'aria-expanded' => false,
27
42
  'aria-label' => 'Toggle navigation'
28
43
  )
29
- prepare_html <<-HTML.chomp!
30
- <button#{toggler_attributes}>
31
- <span class="navbar-toggler-icon"></span>
32
- </button>
33
- <div#{attributes}>
34
- #{capture(&block) if block_given?}
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 <<-HTML.chomp!
44
- <ul#{attributes}>
45
- #{capture(&block) if block_given?}
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)
@@ -58,30 +73,31 @@ 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 <<-HTML.chomp!
62
- <li#{list_item_attributes}>
63
- <a href="#{url}"#{link_attributes}>
64
- #{text}
65
- </a>
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
85
  def navbar_dropdown(text, id = '', list_item_options = {}, link_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(' ')
88
+ wrapper_class = [*list_item_options.delete(:wrapper_class), 'dropdown-menu'].compact.join(' ')
73
89
  list_item_attributes = attributes_for_tag(list_item_options)
74
90
  link_options[:class] = [link_options[:class], 'nav-link', 'dropdown-toggle'].compact.join(' ')
75
91
  id ||= "navbarDropdownMenuLink#{text}"
76
92
  link_attributes = attributes_for_tag(link_options)
77
- prepare_html <<-HTML.chomp!
78
- <li#{list_item_attributes}>
79
- <a href="#" data-toggle="dropdown" id="##{id}" aria-haspopup="true" aria-expanded="false" role="button" #{link_attributes}>#{text}</a>
80
- <div class="dropdown-menu" aria-labelledby="#{id}">
81
- #{capture(&block) if block_given?}
82
- </div>
83
- </li>
84
- HTML
93
+ prepare_html <<~HTML
94
+ <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}">
97
+ #{capture(&block) if block_given?}
98
+ </div>
99
+ </li>
100
+ HTML
85
101
  end
86
102
 
87
103
  def navbar_dropdown_item(text, url = '#', link_options = {}, &block)
@@ -90,36 +106,39 @@ HTML
90
106
  link_options[:class] << 'active' if current_url_or_sub_url?(url)
91
107
  link_options[:class] = link_options[:class].join(' ')
92
108
  link_attributes = attributes_for_tag(link_options)
93
- prepare_html <<~HTML.chomp!
94
- <a href="#{url}"#{link_attributes}>
95
- #{text}
96
- </a>
97
- HTML
109
+ prepare_html <<~HTML
110
+ <a href="#{url}"#{link_attributes}>
111
+ #{text}
112
+ </a>
113
+ HTML
98
114
  end
99
115
 
100
- private
101
-
102
- def container(&block)
103
- prepare_html <<-HTML.chomp!
104
- <div class="container">
105
- #{capture(&block) if block_given?}
106
- </div>
107
- HTML
116
+ def navbar_dropdown_divider
117
+ '<div class="dropdown-divider"></div>'
108
118
  end
109
119
 
110
- def brand_link(text, url = nil)
111
- prepare_html <<-HTML.chomp!
112
- <a href="#{url || '/'}" class="navbar-brand">
113
- #{text}
114
- </a>
115
- HTML
120
+ private
121
+
122
+ def container(container, &block)
123
+ container_class = [
124
+ 'container',
125
+ (container unless container == true)
126
+ ].compact.join('-')
127
+ attributes = attributes_for_tag(class: container_class)
128
+ prepare_html <<~HTML
129
+ <div#{attributes}>
130
+ #{capture(&block) if block_given?}
131
+ </div>
132
+ HTML
116
133
  end
117
134
 
118
135
  def wrapper(options, &block)
119
136
  options = options.dup
120
137
  options[:class] = [options[:class], 'navbar'].compact
121
138
  options[:class] << "navbar-#{options.key?(:color_scheme) ? options.delete(:color_scheme) : 'dark'}"
122
- options[:class] << "bg-#{options.delete(:bg) || 'dark'}" unless options[:bg] == false
139
+ if bg = options.delete(:bg)
140
+ options[:class] << "bg-#{bg == true ? 'dark' : bg}"
141
+ end
123
142
  if options.key?(:sticky) && options.delete(:sticky) === true
124
143
  options[:class] << 'sticky-top'
125
144
  elsif options.key?(:placement)
@@ -127,13 +146,12 @@ HTML
127
146
  end
128
147
  options[:class] << "navbar-expand-#{options.delete(:expand_at) || 'sm'}"
129
148
  options[:class] = options[:class].join(' ')
130
- brand = brand_link(options.delete(:brand), options.delete(:brand_url)) if options[:brand]
131
149
  attributes = attributes_for_tag(options)
132
- prepare_html <<-HTML.chomp!
133
- <nav#{attributes}>
134
- #{brand}
135
- #{capture(&block) if block_given?}
136
- </nav>
137
- HTML
150
+ prepare_html <<~HTML
151
+ <nav#{attributes}>
152
+ #{brand}
153
+ #{capture(&block) if block_given?}
154
+ </nav>
155
+ HTML
138
156
  end
139
157
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapNavbar
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.6'
3
3
  end
@@ -38,7 +38,7 @@ describe BootstrapNavbar::Helpers::Bootstrap4 do
38
38
 
39
39
  context 'with "placement" parameter' do
40
40
  it 'generates the correct HTML' do
41
- %w(full fixed-top fixed-bottom).each do |placement|
41
+ %w(top bottom).each do |placement|
42
42
  expect(renderer.navbar(placement: placement)).to have_tag(:nav, with: { class: "navbar navbar-dark bg-dark fixed-#{placement}" })
43
43
  end
44
44
  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.1
4
+ version: 3.0.6
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: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2020-10-08 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
- rubyforge_project:
172
- rubygems_version: 2.7.5
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: