bootstrap-navbar 2.3.0 → 2.4.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: 982a971198be58abfb4bca9437f239d32649042a
4
- data.tar.gz: ce65e2dfd1f6a41baae61ae60ced9e19a3b0d649
3
+ metadata.gz: ca443255cbdf271153acd52fa96e6d787f4cc391
4
+ data.tar.gz: 1450fb288c7eff37123cf59c4b6e4a1261f966d1
5
5
  SHA512:
6
- metadata.gz: 440b131c834bccd2fa760c715e0a956a933ffad6f1d1e37ddf8f03e710bb4a2f53426285c378a579d1c63d39c54c9fbb46cf29812eb7c89f00596dc7f5d5554f
7
- data.tar.gz: c801f1ba40965ef2479e8bf1d44bb9b4ded164891cb1a79f77e0eaa6db7e0c187083353aa95e271cb451f343f51f94452dd2fbb5b5ed76bba35ae34fb011a018
6
+ metadata.gz: 0ad5a23c193df18e26bbaec8b687a9697b1b1d165d626e50e424b1049764c381fa891de3771af7cf92fe5bc41c9c114cfb092968b852dd20fb5a1f6146b359fd
7
+ data.tar.gz: 47bd7e4873484fa597d5d2b378cda36c03f9a0815850987d7fbe4bed71a8ddc3d66188e9c141529c2351b750c8334ee3c255e9538b856b662896c836fba5e8bc
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.1
3
+ - 2.2.6
4
+ - 2.3.3
5
+ - 2.4.0
5
6
  before_install:
6
7
  - gem update --system
7
8
  - gem update bundler
data/README.md CHANGED
@@ -58,6 +58,23 @@ module BootstrapNavbar::Helpers
58
58
  end
59
59
  ```
60
60
 
61
+ ### Set up root paths (optional)
62
+
63
+ When deciding whether a navbar link is marked as current, the following steps are followed:
64
+
65
+ * If the link target is one of the root paths (only "/" by default), the link is only marked as current if the target is the current path.
66
+ * Otherwise the link is marked as current if the target is the current path or a sub path of the current path.
67
+
68
+ In certain cases a website might want to treat more paths as root paths, e.g. when it has different locales mapped at /en, /de etc. This can be achieved by setting the `root_paths` configuration.
69
+
70
+ ```ruby
71
+ BootstrapNavbar.configure do |config|
72
+ config.root_paths = ['/', '/en', '/de'] # default: ['/']
73
+ end
74
+ ```
75
+
76
+ With this configuration, if your brand link would be '/en' for example, it would not be marked as current if you are on '/en/some-page'.
77
+
61
78
  ### Mix in the helpers into the rendering engine (required)
62
79
 
63
80
  ```ruby
@@ -4,8 +4,9 @@ module BootstrapNavbar
4
4
  include GemConfig::Base
5
5
 
6
6
  with_configuration do
7
- has :bootstrap_version, classes: String
7
+ has :bootstrap_version, classes: String
8
8
  has :current_url_method, classes: String
9
+ has :root_paths, classes: Array, default: %w(/)
9
10
  end
10
11
  end
11
12
 
@@ -31,8 +31,13 @@ module BootstrapNavbar::Helpers
31
31
  normalized_path, normalized_current_path = [uri, current_uri].map do |uri|
32
32
  uri.path.sub(%r(/\z), '')
33
33
  end
34
- if normalized_path.empty?
35
- normalized_current_path.empty?
34
+ normalized_root_paths = BootstrapNavbar.configuration.root_paths.map do |path|
35
+ path.sub(%r(/\z), '')
36
+ end
37
+ # If the URL is one of the root URLS, it's only current if it is the current URL.
38
+ # Otherwise it's current if we're currently on the URL or on a sub URL.
39
+ if normalized_root_paths.include?(normalized_path)
40
+ normalized_current_path == normalized_path
36
41
  else
37
42
  normalized_current_path =~ %r(\A#{Regexp.escape(normalized_path)}(/.+)?\z)
38
43
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapNavbar
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
3
3
  end
@@ -16,7 +16,7 @@ module Helpers
16
16
  end
17
17
 
18
18
  shared_examples 'marking the navbar items as active correctly' do
19
- context 'when the navbar item URL is the current root URL or root path' do
19
+ context 'when the navbar item URL is the current root URL or path' do
20
20
  it_behaves_like 'marking current URLs as current and non-current URLs as not-current' do
21
21
  let(:navbar_item_urls) do
22
22
  %w(
@@ -39,14 +39,52 @@ shared_examples 'marking the navbar items as active correctly' do
39
39
  end
40
40
  end
41
41
 
42
+ context 'when another root path is configured and the navbar item URL is the corresponding root URL or path' do
43
+ before do
44
+ @_previous_root_paths = BootstrapNavbar.configuration.root_paths
45
+ BootstrapNavbar.configuration.root_paths = %w(/custom-root)
46
+ end
47
+
48
+ after do
49
+ BootstrapNavbar.configuration.root_paths = @_previous_root_paths
50
+ end
51
+
52
+ it_behaves_like 'marking current URLs as current and non-current URLs as not-current' do
53
+ let(:navbar_item_urls) do
54
+ %w(
55
+ http://www.foobar.com/custom-root/
56
+ http://www.foobar.com/custom-root
57
+ /custom-root/
58
+ /custom-root
59
+ )
60
+ end
61
+ let(:current_urls) do
62
+ %w(
63
+ http://www.foobar.com/custom-root/
64
+ http://www.foobar.com/custom-root
65
+ )
66
+ end
67
+ let(:non_current_urls) do
68
+ %w(
69
+ http://www.foobar.com/
70
+ http://www.foobar.com
71
+ http://www.foobar.com/foo/
72
+ http://www.foobar.com/foo
73
+ http://www.foobar.com/custom-root/foo/
74
+ http://www.foobar.com/custom-root/foo
75
+ )
76
+ end
77
+ end
78
+ end
79
+
42
80
  context 'when the navbar item URL is a sub URL of the current URL' do
43
81
  it_behaves_like 'marking current URLs as current and non-current URLs as not-current' do
44
82
  let(:navbar_item_urls) do
45
83
  %w(
46
84
  http://www.foobar.com/foo/
47
85
  http://www.foobar.com/foo
48
- /foo
49
86
  /foo/
87
+ /foo
50
88
  )
51
89
  end
52
90
  let(:current_urls) do
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: 2.3.0
4
+ version: 2.4.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: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.6.6
158
+ rubygems_version: 2.6.8
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Helpers to generate a Bootstrap style navbar
@@ -166,4 +166,3 @@ test_files:
166
166
  - spec/bootstrap-navbar/helpers_spec.rb
167
167
  - spec/spec_helper.rb
168
168
  - spec/support/helpers.rb
169
- has_rdoc: