simple-navigation 4.4.1 → 4.5.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 +4 -4
- data/.github/workflows/ci.yml +84 -0
- data/.rspec +1 -2
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +38 -0
- data/Appraisals +55 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +21 -0
- data/Guardfile +4 -2
- data/README.md +11 -23
- data/Rakefile +2 -27
- data/bin/_guard-core +16 -0
- data/bin/appraisal +16 -0
- data/bin/guard +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/gemfiles/rails_6.1.gemfile +35 -0
- data/gemfiles/rails_7.0.gemfile +23 -0
- data/gemfiles/rails_7.1.gemfile +23 -0
- data/gemfiles/rails_7.2.gemfile +23 -0
- data/gemfiles/rails_8.0.gemfile +23 -0
- data/gemfiles/rails_8.1.gemfile +23 -0
- data/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/generators/navigation_config/templates/config/navigation.rb +30 -26
- data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
- data/lib/simple-navigation.rb +3 -1
- data/lib/simple_navigation/adapters/base.rb +2 -0
- data/lib/simple_navigation/adapters/nanoc.rb +8 -3
- data/lib/simple_navigation/adapters/padrino.rb +3 -1
- data/lib/simple_navigation/adapters/rails.rb +12 -14
- data/lib/simple_navigation/adapters/sinatra.rb +4 -6
- data/lib/simple_navigation/config_file.rb +1 -1
- data/lib/simple_navigation/config_file_finder.rb +3 -3
- data/lib/simple_navigation/configuration.rb +5 -5
- data/lib/simple_navigation/helpers.rb +9 -11
- data/lib/simple_navigation/item.rb +26 -20
- data/lib/simple_navigation/item_adapter.rb +16 -5
- data/lib/simple_navigation/item_container.rb +13 -7
- data/lib/simple_navigation/items_provider.rb +6 -4
- data/lib/simple_navigation/railtie.rb +3 -1
- data/lib/simple_navigation/renderer/base.rb +5 -5
- data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
- data/lib/simple_navigation/renderer/json.rb +1 -1
- data/lib/simple_navigation/renderer/links.rb +2 -0
- data/lib/simple_navigation/renderer/list.rb +5 -5
- data/lib/simple_navigation/renderer/text.rb +3 -1
- data/lib/simple_navigation/version.rb +3 -1
- data/lib/simple_navigation.rb +32 -24
- data/simple-navigation.gemspec +16 -27
- data/spec/fake_app/config/navigation.rb +4 -2
- data/spec/fake_app/rails_app.rb +5 -3
- data/spec/integration/rendering_navigation_spec.rb +7 -5
- data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
- data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
- data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
- data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
- data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
- data/spec/simple_navigation/config_file_spec.rb +14 -14
- data/spec/simple_navigation/configuration_spec.rb +128 -121
- data/spec/simple_navigation/helpers_spec.rb +282 -284
- data/spec/simple_navigation/item_adapter_spec.rb +109 -122
- data/spec/simple_navigation/item_container_spec.rb +407 -408
- data/spec/simple_navigation/item_spec.rb +333 -301
- data/spec/simple_navigation/items_provider_spec.rb +30 -27
- data/spec/simple_navigation/renderer/base_spec.rb +166 -168
- data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
- data/spec/simple_navigation/renderer/json_spec.rb +49 -56
- data/spec/simple_navigation/renderer/links_spec.rb +81 -83
- data/spec/simple_navigation/renderer/list_spec.rb +111 -91
- data/spec/simple_navigation/renderer/text_spec.rb +37 -39
- data/spec/simple_navigation_spec.rb +54 -47
- data/spec/spec_helper.rb +146 -53
- metadata +25 -164
- data/.travis.yml +0 -23
- data/gemfiles/rails-3-2-stable.gemfile +0 -11
- data/gemfiles/rails-4-1-stable.gemfile +0 -7
- data/gemfiles/rails-4-2-stable.gemfile +0 -7
- data/gemfiles/rails-5-2-stable.gemfile +0 -7
- data/gemfiles/rails-6-0-stable.gemfile +0 -9
- data/gemfiles/rails-6-1-stable.gemfile +0 -9
- data/init.rb +0 -1
- data/install.rb +0 -5
- data/lib/simple_navigation/adapters.rb +0 -10
- data/lib/simple_navigation/renderer.rb +0 -12
- data/spec/initializers/coveralls.rb +0 -3
- data/spec/initializers/have_css_matcher.rb +0 -19
- data/spec/initializers/memfs.rb +0 -7
- data/spec/initializers/rails.rb +0 -4
- data/spec/initializers/rspec.rb +0 -7
- data/uninstall.rb +0 -1
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
describe ItemsProvider do
|
|
3
|
-
let(:items_provider) { ItemsProvider.new(provider) }
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
RSpec.describe SimpleNavigation::ItemsProvider do
|
|
4
|
+
let(:items_provider) { described_class.new(provider) }
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let(:provider) { :provider_method }
|
|
6
|
+
describe '#items' do
|
|
7
|
+
let(:items) { double(:items) }
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
context 'when provider is a symbol' do
|
|
10
|
+
let(:context) { double(:context, provider_method: items) }
|
|
11
|
+
let(:provider) { :provider_method }
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
before { allow(SimpleNavigation).to receive_messages(context_for_eval: context) }
|
|
14
|
+
|
|
15
|
+
it 'retrieves the items from the evaluation context' do
|
|
16
|
+
expect(items_provider.items).to eq items
|
|
17
17
|
end
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
context 'when provider responds to :items' do
|
|
21
|
+
let(:provider) { double(:provider, items: items) }
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
23
|
+
it 'retrieves the items from the provider object' do
|
|
24
|
+
expect(items_provider.items).to eq items
|
|
25
25
|
end
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
context 'when provider is a collection' do
|
|
29
|
+
let(:provider) { [] }
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
31
|
+
it 'retrieves the items by returning the provider' do
|
|
32
|
+
expect(items_provider.items).to eq provider
|
|
33
33
|
end
|
|
34
|
+
end
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
context 'when provider is something else' do
|
|
37
|
+
let(:provider) { double(:provider) }
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
it 'raises an exception' do
|
|
40
|
+
expect do
|
|
41
|
+
items_provider.items
|
|
42
|
+
end.to raise_error(RuntimeError,
|
|
43
|
+
/items_provider either must be a symbol .*, an object .* or an enumerable/)
|
|
41
44
|
end
|
|
42
45
|
end
|
|
43
46
|
end
|
|
@@ -1,238 +1,236 @@
|
|
|
1
|
-
|
|
2
|
-
module Renderer
|
|
3
|
-
describe Base do
|
|
4
|
-
subject(:base) { Base.new(options) }
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
RSpec.describe SimpleNavigation::Renderer::Base do
|
|
4
|
+
subject(:base) { described_class.new(options) }
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
let(:adapter) { double(:adapter) }
|
|
7
|
+
let(:options) { {} }
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
allow(adapter).to receive_messages(link_to: 'link_to')
|
|
13
|
-
expect(base.link_to).to eq 'link_to'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'delegates the :content_tag method to adapter' do
|
|
17
|
-
allow(adapter).to receive_messages(content_tag: 'content_tag')
|
|
18
|
-
expect(base.content_tag).to eq 'content_tag'
|
|
19
|
-
end
|
|
9
|
+
before { allow(SimpleNavigation).to receive_messages(adapter: adapter) }
|
|
20
10
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end
|
|
11
|
+
it 'delegates the :link_to method to adapter' do
|
|
12
|
+
allow(adapter).to receive_messages(link_to: 'link_to')
|
|
13
|
+
expect(base.link_to).to eq 'link_to'
|
|
14
|
+
end
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
16
|
+
it 'delegates the :content_tag method to adapter' do
|
|
17
|
+
allow(adapter).to receive_messages(content_tag: 'content_tag')
|
|
18
|
+
expect(base.content_tag).to eq 'content_tag'
|
|
19
|
+
end
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
describe '#initialize' do
|
|
22
|
+
it 'sets the renderer adapter to the SimpleNavigation one' do
|
|
23
|
+
expect(base.adapter).to be adapter
|
|
24
|
+
end
|
|
25
|
+
end
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
describe '#options' do
|
|
28
|
+
it "returns the renderer's options" do
|
|
29
|
+
expect(base.options).to be options
|
|
30
|
+
end
|
|
31
|
+
end
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
describe '#render' do
|
|
34
|
+
it "raise an exception to indicate it's a subclass responsibility" do
|
|
35
|
+
expect { base.render(:container) }.to raise_error(NotImplementedError, 'subclass responsibility')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
describe '#expand_all?' do
|
|
40
|
+
context 'when :options is set' do
|
|
41
|
+
context 'when the :expand_all option is true' do
|
|
42
|
+
let(:options) { { expand_all: true } }
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
end
|
|
44
|
+
it 'returns true' do
|
|
45
|
+
expect(base.expand_all?).to be true
|
|
56
46
|
end
|
|
47
|
+
end
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
context 'when the :expand_all option is false' do
|
|
50
|
+
let(:options) { { expand_all: false } }
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
end
|
|
52
|
+
it 'returns false' do
|
|
53
|
+
expect(base.expand_all?).to be false
|
|
64
54
|
end
|
|
65
55
|
end
|
|
56
|
+
end
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
context 'and the :skip_if_empty option is true' do
|
|
70
|
-
let(:options) {{ skip_if_empty: true }}
|
|
58
|
+
context "when :options isn't set" do
|
|
59
|
+
let(:options) { {} }
|
|
71
60
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
it 'returns false' do
|
|
62
|
+
expect(base.expand_all?).to be false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
76
66
|
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
describe '#skip_if_empty?' do
|
|
68
|
+
context 'when :options is set' do
|
|
69
|
+
context 'when the :skip_if_empty option is true' do
|
|
70
|
+
let(:options) { { skip_if_empty: true } }
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
end
|
|
83
|
-
end
|
|
72
|
+
it 'returns true' do
|
|
73
|
+
expect(base.skip_if_empty?).to be true
|
|
84
74
|
end
|
|
75
|
+
end
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
context 'when the :skip_if_empty option is false' do
|
|
78
|
+
let(:options) { { skip_if_empty: false } }
|
|
88
79
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
80
|
+
it 'returns true' do
|
|
81
|
+
expect(base.skip_if_empty?).to be false
|
|
92
82
|
end
|
|
93
83
|
end
|
|
84
|
+
end
|
|
94
85
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let(:options) {{ level: 1 }}
|
|
86
|
+
context "when :options isn't set" do
|
|
87
|
+
let(:options) { {} }
|
|
98
88
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
it 'returns true' do
|
|
90
|
+
expect(base.skip_if_empty?).to be false
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
103
94
|
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
describe '#level' do
|
|
96
|
+
context 'when the :level option is set' do
|
|
97
|
+
let(:options) { { level: 1 } }
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
end
|
|
99
|
+
it 'returns the specified level' do
|
|
100
|
+
expect(base.level).to eq 1
|
|
111
101
|
end
|
|
102
|
+
end
|
|
112
103
|
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
context "when the :level option isn't set" do
|
|
105
|
+
let(:options) { {} }
|
|
115
106
|
|
|
116
|
-
|
|
107
|
+
it 'returns :all' do
|
|
108
|
+
expect(base.level).to eq :all
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
describe '#consider_sub_navigation?' do
|
|
114
|
+
let(:item) { double(:item) }
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
expect(base.send(:consider_sub_navigation?, item)).to be false
|
|
123
|
-
end
|
|
124
|
-
end
|
|
116
|
+
before { allow(item).to receive_messages(sub_navigation: sub_navigation) }
|
|
125
117
|
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
context 'when the item has no sub navigation' do
|
|
119
|
+
let(:sub_navigation) { nil }
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
it 'returns false' do
|
|
122
|
+
expect(base.send(:consider_sub_navigation?, item)).to be false
|
|
123
|
+
end
|
|
124
|
+
end
|
|
131
125
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
end
|
|
135
|
-
end
|
|
126
|
+
context 'when the item has sub navigation' do
|
|
127
|
+
let(:sub_navigation) { double(:sub_navigation) }
|
|
136
128
|
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
context 'when the renderer has an unknown level' do
|
|
130
|
+
before { allow(base).to receive_messages(level: 'unknown') }
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
it 'returns false' do
|
|
133
|
+
expect(base.send(:consider_sub_navigation?, item)).to be false
|
|
134
|
+
end
|
|
135
|
+
end
|
|
144
136
|
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
context 'when the renderer has a level set to :all' do
|
|
138
|
+
before { allow(base).to receive_messages(level: :all) }
|
|
147
139
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
it 'returns false' do
|
|
141
|
+
expect(base.send(:consider_sub_navigation?, item)).to be true
|
|
142
|
+
end
|
|
143
|
+
end
|
|
152
144
|
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
context "when the renderer's level is a number" do
|
|
146
|
+
before { allow(base).to receive_messages(level: 2) }
|
|
155
147
|
|
|
156
|
-
|
|
157
|
-
|
|
148
|
+
it 'returns false' do
|
|
149
|
+
expect(base.send(:consider_sub_navigation?, item)).to be false
|
|
150
|
+
end
|
|
151
|
+
end
|
|
158
152
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
end
|
|
162
|
-
end
|
|
153
|
+
context "when the renderer's level is a Range" do
|
|
154
|
+
before { allow(base).to receive_messages(level: 2..3) }
|
|
163
155
|
|
|
164
|
-
|
|
165
|
-
|
|
156
|
+
context "when sub navigation's level is greater than range.max" do
|
|
157
|
+
before { allow(sub_navigation).to receive_messages(level: 4) }
|
|
166
158
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
it 'returns false' do
|
|
160
|
+
expect(base.send(:consider_sub_navigation?, item)).to be false
|
|
161
|
+
end
|
|
162
|
+
end
|
|
171
163
|
|
|
172
|
-
|
|
173
|
-
|
|
164
|
+
context "when sub navigation's level is equal to range.max" do
|
|
165
|
+
before { allow(sub_navigation).to receive_messages(level: 3) }
|
|
174
166
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
end
|
|
178
|
-
end
|
|
167
|
+
it 'returns true' do
|
|
168
|
+
expect(base.send(:consider_sub_navigation?, item)).to be true
|
|
179
169
|
end
|
|
180
170
|
end
|
|
181
|
-
end
|
|
182
171
|
|
|
183
|
-
|
|
184
|
-
|
|
172
|
+
context "when sub navigation's level is equal to range.min" do
|
|
173
|
+
before { allow(sub_navigation).to receive_messages(level: 2) }
|
|
185
174
|
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
it 'returns true' do
|
|
176
|
+
expect(base.send(:consider_sub_navigation?, item)).to be true
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
188
182
|
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
describe '#include_sub_navigation?' do
|
|
184
|
+
let(:item) { double(:item) }
|
|
191
185
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
end
|
|
195
|
-
end
|
|
186
|
+
context 'when consider_sub_navigation? is true' do
|
|
187
|
+
before { allow(base).to receive_messages(consider_sub_navigation?: true) }
|
|
196
188
|
|
|
197
|
-
|
|
198
|
-
|
|
189
|
+
context 'when expand_sub_navigation? is true' do
|
|
190
|
+
before { allow(base).to receive_messages(expand_sub_navigation?: true) }
|
|
199
191
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
end
|
|
203
|
-
end
|
|
192
|
+
it 'returns true' do
|
|
193
|
+
expect(base.include_sub_navigation?(item)).to be true
|
|
204
194
|
end
|
|
195
|
+
end
|
|
205
196
|
|
|
206
|
-
|
|
207
|
-
|
|
197
|
+
context 'when expand_sub_navigation? is false' do
|
|
198
|
+
before { allow(base).to receive_messages(expand_sub_navigation?: false) }
|
|
208
199
|
|
|
209
|
-
|
|
210
|
-
|
|
200
|
+
it 'returns false' do
|
|
201
|
+
expect(base.include_sub_navigation?(item)).to be false
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
211
205
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
end
|
|
215
|
-
end
|
|
206
|
+
context 'when consider_sub_navigation? is false' do
|
|
207
|
+
before { allow(base).to receive_messages(consider_sub_navigation?: false) }
|
|
216
208
|
|
|
217
|
-
|
|
218
|
-
|
|
209
|
+
context 'when expand_sub_navigation? is true' do
|
|
210
|
+
before { allow(base).to receive_messages(expand_sub_navigation?: true) }
|
|
219
211
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
end
|
|
223
|
-
end
|
|
212
|
+
it 'returns false' do
|
|
213
|
+
expect(base.include_sub_navigation?(item)).to be false
|
|
224
214
|
end
|
|
225
215
|
end
|
|
226
216
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
let(:sub_navigation) { double(:sub_navigation) }
|
|
217
|
+
context 'when expand_sub_navigation? is false' do
|
|
218
|
+
before { allow(base).to receive_messages(expand_sub_navigation?: false) }
|
|
230
219
|
|
|
231
|
-
it '
|
|
232
|
-
expect(
|
|
233
|
-
base.render_sub_navigation_for(item)
|
|
220
|
+
it 'returns false' do
|
|
221
|
+
expect(base.include_sub_navigation?(item)).to be false
|
|
234
222
|
end
|
|
235
223
|
end
|
|
236
224
|
end
|
|
237
225
|
end
|
|
226
|
+
|
|
227
|
+
describe '#render_sub_navigation_for' do
|
|
228
|
+
let(:item) { double(:item, sub_navigation: sub_navigation) }
|
|
229
|
+
let(:sub_navigation) { double(:sub_navigation) }
|
|
230
|
+
|
|
231
|
+
it 'renders the sub navigation passing it the options' do
|
|
232
|
+
expect(sub_navigation).to receive(:render).with(options)
|
|
233
|
+
base.render_sub_navigation_for(item)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
238
236
|
end
|