bootstrap-navbar 2.0.0 → 2.1.0

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
  SHA1:
3
- metadata.gz: 781cad4ac31fafee2286b64f3724c8b5cd4a3ed2
4
- data.tar.gz: b0d3f73b9c98ed24f2f65216d3ff313249964e56
3
+ metadata.gz: 048ac7040b82f5137e124b8b88c643f29f201e02
4
+ data.tar.gz: e136412ed6a30340559891cf75dd817017b0eb3f
5
5
  SHA512:
6
- metadata.gz: 88d37fed5dd7c408fb4e69cae5ee66c476dca8b96967afce12ed6d21b3a4770ac2457c6677700ba2ef5c2ea8ee670a96b8454635976d79355d9d732383be5ba8
7
- data.tar.gz: a33caba3b1d44fedba100e33ccb2c7e167b88dbc87ddbd6a4ddae14a3be19fd5d9ed2d2dde8772550321f4deaec4a1d99a036370f42c3686a1aa22626abd7207
6
+ metadata.gz: a386f61fc104b587b99477a2688abff2bef7763ef625e6534ab80a43a7b09d6356e93665f2d488ef8b38c2e143bb63c0d3b6ff51680f774334fa36797f8880c5
7
+ data.tar.gz: e35fa7f421ba27835024c8639f731a4021968d38607d2e935979f61be794a6efd7ce5019fda1eb27c2f17a22432a493d9b2b8842a3dcc772fb7c432b732323e2
@@ -29,5 +29,5 @@ Gem::Specification.new do |gem|
29
29
  # Listen >= 2.0.0 only works with Ruby >= 1.9.3
30
30
  gem.add_development_dependency 'listen', '< 2.0.0' if RUBY_VERSION < '1.9.3'
31
31
  gem.add_development_dependency 'bootstrap-sass', '3.0.2.0'
32
- gem.add_runtime_dependency 'gem_config', '~> 0.2.4'
32
+ gem.add_runtime_dependency 'gem_config', '~> 0.3.0'
33
33
  end
@@ -4,7 +4,7 @@ module BootstrapNavbar
4
4
  include GemConfig::Base
5
5
 
6
6
  with_configuration do
7
- has :bootstrap_version, classes: [String, NilClass]
7
+ has :bootstrap_version, classes: String
8
8
  has :current_url_method, classes: String
9
9
  end
10
10
  end
@@ -22,11 +22,15 @@ module BootstrapNavbar::Helpers
22
22
  end
23
23
  end
24
24
 
25
- def current_url?(url)
25
+ def current_url_or_sub_url?(url)
26
26
  normalized_path, normalized_current_path = [url, current_url].map do |url|
27
- URI.parse(url).path.sub(%r(/\z), '') rescue nil
27
+ URI.parse(url).path.sub(%r(/\z), '')
28
+ end
29
+ if normalized_path.empty?
30
+ normalized_current_path.empty?
31
+ else
32
+ normalized_current_path =~ %r(#{Regexp.escape(normalized_path)}(/.+)?)
28
33
  end
29
- normalized_path == normalized_current_path
30
34
  end
31
35
 
32
36
  def current_url
@@ -27,7 +27,7 @@ HTML
27
27
  list_item_options = list_item_options.nil? ? {} : list_item_options.dup
28
28
  link_options = link_options.nil? ? {} : link_options.dup
29
29
  list_item_css_classes = [].tap do |css_classes|
30
- css_classes << 'active' if current_url?(path)
30
+ css_classes << 'active' if current_url_or_sub_url?(path)
31
31
  css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
32
32
  end
33
33
  list_item_attributes = attributes_for_tag(
@@ -65,7 +65,7 @@ HTML
65
65
  list_item_options = list_item_options.nil? ? {} : list_item_options.dup
66
66
  link_options = link_options.nil? ? {} : link_options.dup
67
67
  list_item_css_classes = [].tap do |css_classes|
68
- css_classes << 'active' if current_url?(url)
68
+ css_classes << 'active' if current_url_or_sub_url?(url)
69
69
  css_classes << list_item_options.delete(:class) if list_item_options.has_key?(:class)
70
70
  end
71
71
  list_item_attributes = attributes_for_tag(
@@ -1,3 +1,3 @@
1
1
  module BootstrapNavbar
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -1,16 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples 'active menu item' do
4
- it 'generates the correct HTML' do
5
- paths_and_urls.each do |current_path_or_url|
6
- paths_and_urls.each do |menu_path_or_url|
7
- BootstrapNavbar.configuration.current_url_method = "'#{current_path_or_url}'"
8
- expect(renderer.navbar_item('foo', menu_path_or_url)).to have_tag(:li, with: { class: 'active' })
9
- end
10
- end
11
- end
12
- end
13
-
14
3
  describe BootstrapNavbar::Helpers::Bootstrap2 do
15
4
  before do
16
5
  BootstrapNavbar.configure do |config|
@@ -132,51 +121,9 @@ describe BootstrapNavbar::Helpers::Bootstrap2 do
132
121
  end
133
122
 
134
123
  describe '#navbar_item' do
135
- context 'with current URL or path' do
136
- # With root URL or path
137
- it_behaves_like 'active menu item' do
138
- let(:paths_and_urls) do
139
- %w(
140
- http://www.foobar.com/
141
- http://www.foobar.com
142
- /
143
- http://www.foobar.com/?foo=bar
144
- http://www.foobar.com?foo=bar
145
- /?foo=bar
146
- http://www.foobar.com/#foo
147
- http://www.foobar.com#foo
148
- /#foo
149
- http://www.foobar.com/#foo?foo=bar
150
- http://www.foobar.com#foo?foo=bar
151
- /#foo?foo=bar
152
- )
153
- end
154
- end
155
-
156
- # With sub URL or path
157
- it_behaves_like 'active menu item' do
158
- let(:paths_and_urls) do
159
- %w(
160
- http://www.foobar.com/foo
161
- http://www.foobar.com/foo/
162
- /foo
163
- /foo/
164
- http://www.foobar.com/foo?foo=bar
165
- http://www.foobar.com/foo/?foo=bar
166
- /foo?foo=bar
167
- /foo/?foo=bar
168
- http://www.foobar.com/foo#foo
169
- http://www.foobar.com/foo/#foo
170
- /foo#foo
171
- /foo/#foo
172
- http://www.foobar.com/foo#foo?foo=bar
173
- http://www.foobar.com/foo/#foo?foo=bar
174
- /foo#foo?foo=bar
175
- /foo/#foo?foo=bar
176
- )
177
- end
178
- end
124
+ it_behaves_like 'marking the menu items as active correctly'
179
125
 
126
+ context 'with root URL' do
180
127
  context 'with list item options' do
181
128
  it 'generates the correct HTML' do
182
129
  BootstrapNavbar.configuration.current_url_method = '"/"'
@@ -1,18 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples 'active navbar link' do
4
- it 'generates the correct HTML' do
5
- paths_and_urls.each do |current_path_or_url|
6
- paths_and_urls.each do |menu_path_or_url|
7
- BootstrapNavbar.configuration.current_url_method = "'#{current_path_or_url}'"
8
- expect(renderer.navbar_item('foo', menu_path_or_url)).to have_tag(:li, with: { class: 'active' }) do
9
- with_tag :a, with: { href: menu_path_or_url }, text: /foo/
10
- end
11
- end
12
- end
13
- end
14
- end
15
-
16
3
  describe BootstrapNavbar::Helpers::Bootstrap3 do
17
4
  before do
18
5
  BootstrapNavbar.configure do |config|
@@ -67,10 +54,9 @@ describe BootstrapNavbar::Helpers::Bootstrap3 do
67
54
  end
68
55
  end
69
56
  end
70
-
71
57
  end
72
58
 
73
- describe '#navbar_header',:focus do
59
+ describe '#navbar_header' do
74
60
  context 'without parameters' do
75
61
  it 'generates the correct HTML' do
76
62
  expect(renderer.navbar_header { 'foo' }).to have_tag :div, with: { class: 'navbar-header' } do
@@ -98,7 +84,7 @@ describe BootstrapNavbar::Helpers::Bootstrap3 do
98
84
  end
99
85
  end
100
86
 
101
- describe '#navbar_collapse',:focus do
87
+ describe '#navbar_collapse' do
102
88
  context 'without parameters' do
103
89
  it 'generates the correct HTML' do
104
90
  expect(renderer.navbar_collapse { 'foo' }).to have_tag :div, with: { class: 'collapse navbar-collapse', id: 'navbar-collapsable' }, text: /foo/
@@ -140,51 +126,7 @@ describe BootstrapNavbar::Helpers::Bootstrap3 do
140
126
  end
141
127
 
142
128
  describe '#navbar_item' do
143
- context 'with current URL or path' do
144
- # With root URL or path
145
- it_behaves_like 'active navbar link' do
146
- let(:paths_and_urls) do
147
- %w(
148
- http://www.foobar.com/
149
- http://www.foobar.com
150
- /
151
- http://www.foobar.com/?foo=bar
152
- http://www.foobar.com?foo=bar
153
- /?foo=bar
154
- http://www.foobar.com/#foo
155
- http://www.foobar.com#foo
156
- /#foo
157
- http://www.foobar.com/#foo?foo=bar
158
- http://www.foobar.com#foo?foo=bar
159
- /#foo?foo=bar
160
- )
161
- end
162
- end
163
-
164
- # With sub URL or path
165
- it_behaves_like 'active navbar link' do
166
- let(:paths_and_urls) do
167
- %w(
168
- http://www.foobar.com/foo
169
- http://www.foobar.com/foo/
170
- /foo
171
- /foo/
172
- http://www.foobar.com/foo?foo=bar
173
- http://www.foobar.com/foo/?foo=bar
174
- /foo?foo=bar
175
- /foo/?foo=bar
176
- http://www.foobar.com/foo#foo
177
- http://www.foobar.com/foo/#foo
178
- /foo#foo
179
- /foo/#foo
180
- http://www.foobar.com/foo#foo?foo=bar
181
- http://www.foobar.com/foo/#foo?foo=bar
182
- /foo#foo?foo=bar
183
- /foo/#foo?foo=bar
184
- )
185
- end
186
- end
187
- end
129
+ it_behaves_like 'marking the menu items as active correctly'
188
130
 
189
131
  context 'without current URL' do
190
132
  it 'generates the correct HTML' do
@@ -18,7 +18,7 @@ describe BootstrapNavbar::Helpers do
18
18
 
19
19
  context 'when Bootstrap version is not set' do
20
20
  before do
21
- BootstrapNavbar.configuration.bootstrap_version = nil
21
+ BootstrapNavbar.configuration.unset :bootstrap_version
22
22
  end
23
23
 
24
24
  context 'when bootstrap-sass gem is not loaded' do
@@ -16,3 +16,83 @@ module Helpers
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ shared_examples 'marking the menu items as active correctly' do
21
+ context 'when URL is the root URL' do
22
+ it_behaves_like 'marking current URLs as current and non-current ones not' do
23
+ let(:navbar_item_urls) do
24
+ %w(
25
+ http://www.foobar.com/
26
+ http://www.foobar.com
27
+ /
28
+ )
29
+ end
30
+ let(:current_urls) do
31
+ %w(
32
+ http://www.foobar.com/
33
+ http://www.foobar.com
34
+ /
35
+ )
36
+ end
37
+ let(:non_current_urls) do
38
+ %w(
39
+ http://www.foobar.com/foo
40
+ /foo
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when URL is a sub URL' do
47
+ it_behaves_like 'marking current URLs as current and non-current ones not' do
48
+ let(:navbar_item_urls) do
49
+ %w(
50
+ http://www.foobar.com/foo/
51
+ http://www.foobar.com/foo
52
+ /foo
53
+ /foo/
54
+ )
55
+ end
56
+ let(:current_urls) do
57
+ %w(
58
+ http://www.foobar.com/foo/
59
+ http://www.foobar.com/foo
60
+ /foo
61
+ /foo/
62
+
63
+ http://www.foobar.com/foo/bar/
64
+ http://www.foobar.com/foo/bar
65
+ /foo/bar
66
+ /foo/bar/
67
+ )
68
+ end
69
+ let(:non_current_urls) do
70
+ %w(
71
+ http://www.foobar.com/
72
+ http://www.foobar.com
73
+ /
74
+
75
+ http://www.foobar.com/bar/
76
+ http://www.foobar.com/bar
77
+ /bar
78
+ /bar/
79
+ )
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ shared_examples 'marking current URLs as current and non-current ones not' do
86
+ it 'generates the correct HTML' do
87
+ navbar_item_urls.each do |navbar_item_url|
88
+ current_urls.each do |current_url|
89
+ BootstrapNavbar.configuration.current_url_method = "'#{current_url}'"
90
+ expect(renderer.navbar_item('foo', navbar_item_url)).to have_tag(:li, with: { class: 'active' })
91
+ end
92
+ non_current_urls.each do |non_current_url|
93
+ BootstrapNavbar.configuration.current_url_method = "'#{non_current_url}'"
94
+ expect(renderer.navbar_item('foo', navbar_item_url)).to have_tag(:li, without: { class: 'active' })
95
+ end
96
+ end
97
+ end
98
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-navbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: 0.2.4
103
+ version: 0.3.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: 0.2.4
110
+ version: 0.3.0
111
111
  description: Helpers to generate a Twitter Bootstrap style navbar
112
112
  email: manuel@krautcomputing.com
113
113
  executables: []