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,24 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'simple_navigation/config_file'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
subject(:config_file) { ConfigFile.new(context) }
|
|
5
|
+
RSpec.describe SimpleNavigation::ConfigFile do
|
|
6
|
+
subject(:config_file) { described_class.new(context) }
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
let(:context) { :default }
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
10
|
+
describe '#name' do
|
|
11
|
+
context 'when the context is :default' do
|
|
12
|
+
it 'returns navigation.rb' do
|
|
13
|
+
expect(config_file.name).to eq 'navigation.rb'
|
|
14
14
|
end
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
context 'when the context is different from :default' do
|
|
18
|
+
let(:context) { :HelloWorld }
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
20
|
+
it 'returns UNDERSCORED_CONTEXT_navigation.rb' do
|
|
21
|
+
expect(config_file.name).to eq 'hello_world_navigation.rb'
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -1,164 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
describe Configuration do
|
|
3
|
-
subject(:config) { Configuration.instance }
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
RSpec.describe SimpleNavigation::Configuration do
|
|
4
|
+
subject(:config) { described_class.instance }
|
|
5
|
+
|
|
6
|
+
describe '.run' do
|
|
7
|
+
it 'yields the singleton Configuration object' do
|
|
8
|
+
expect { |blk| described_class.run(&blk) }.to yield_with_args(config)
|
|
9
9
|
end
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
describe '.eval_config' do
|
|
13
|
+
let(:config_files) { { default: 'default', my_context: 'my_context' } }
|
|
14
|
+
let(:eval_context) { double(:eval_context) }
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
before do
|
|
17
|
+
allow(eval_context).to receive(:instance_eval)
|
|
18
|
+
allow(SimpleNavigation).to \
|
|
19
|
+
receive_messages(context_for_eval: eval_context, config_files: config_files)
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end
|
|
22
|
+
context 'with default navigation context' do
|
|
23
|
+
it 'calls instance_eval with the default config_file-string inside the context' do
|
|
24
|
+
expect(eval_context).to receive(:instance_eval).with('default')
|
|
25
|
+
described_class.eval_config
|
|
26
26
|
end
|
|
27
|
+
end
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
29
|
+
context 'with non default navigation context' do
|
|
30
|
+
it 'calls instance_eval with the specified config_file-string inside the context' do
|
|
31
|
+
expect(eval_context).to receive(:instance_eval).with('my_context')
|
|
32
|
+
described_class.eval_config(:my_context)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
describe '#initialize' do
|
|
38
|
+
it 'sets the List-Renderer as default' do
|
|
39
|
+
expect(config.renderer).to be SimpleNavigation::Renderer::List
|
|
40
|
+
end
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
it 'sets the selected_class to "selected" as default' do
|
|
43
|
+
expect(config.selected_class).to eq 'selected'
|
|
44
|
+
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
it 'sets the active_leaf_class to "simple-navigation-active-leaf" as default' do
|
|
47
|
+
expect(config.active_leaf_class).to eq 'simple-navigation-active-leaf'
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
it 'sets autogenerate_item_ids to true as default' do
|
|
51
|
+
expect(config.autogenerate_item_ids).to be true
|
|
52
|
+
end
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
it 'sets auto_highlight to true as default' do
|
|
55
|
+
expect(config.auto_highlight).to be true
|
|
56
|
+
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
it 'sets the id_generator to a callable object' do
|
|
59
|
+
expect(config.id_generator).to respond_to(:call)
|
|
60
|
+
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
it 'sets the name_generator to a callable object' do
|
|
63
|
+
expect(config.name_generator).to respond_to(:call)
|
|
64
|
+
end
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
it 'sets the consider_item_names_as_safe to false' do
|
|
67
|
+
expect(config.consider_item_names_as_safe).to be false
|
|
68
|
+
end
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
it 'sets ignore_query_params_on_auto_highlight to true as default' do
|
|
74
|
-
expect(config.ignore_query_params_on_auto_highlight).to be true
|
|
75
|
-
end
|
|
70
|
+
it 'sets highlights_on_subpath to false as default' do
|
|
71
|
+
expect(config.highlight_on_subpath).to be false
|
|
72
|
+
end
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
it 'sets ignore_query_params_on_auto_highlight to true as default' do
|
|
75
|
+
expect(config.ignore_query_params_on_auto_highlight).to be true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'sets ignore_anchors_on_auto_highlight to true as default' do
|
|
79
|
+
expect(config.ignore_anchors_on_auto_highlight).to be true
|
|
80
80
|
end
|
|
81
|
+
end
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
describe '#items' do
|
|
84
|
+
let(:container) { double(:items_container) }
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
before { allow(SimpleNavigation::ItemContainer).to receive_messages(new: container) }
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
context 'when a block is given' do
|
|
89
|
+
context 'when items_provider is specified' do
|
|
90
|
+
let(:provider) { double(:provider) }
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
it 'raises an exception' do
|
|
93
|
+
# rubocop:disable Lint/EmptyBlock
|
|
94
|
+
expect do
|
|
95
|
+
config.items(provider) do
|
|
96
|
+
end
|
|
97
|
+
end.to raise_error(RuntimeError, 'please specify either items_provider or block, but not both')
|
|
98
|
+
# rubocop:enable Lint/EmptyBlock
|
|
94
99
|
end
|
|
100
|
+
end
|
|
95
101
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
context 'when no items_provider is specified' do
|
|
103
|
+
it 'yields an new ItemContainer' do
|
|
104
|
+
expect { |blk| config.items(&blk) }.to yield_with_args(container)
|
|
105
|
+
end
|
|
100
106
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
it 'assigns the ItemContainer to an instance-var' do
|
|
108
|
+
config.items {} # rubocop:disable Lint/EmptyBlock
|
|
109
|
+
expect(config.primary_navigation).to be container
|
|
110
|
+
end
|
|
105
111
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
112
|
+
it "doesn't set the items on the container" do
|
|
113
|
+
expect(container).not_to receive(:items=)
|
|
114
|
+
config.items {} # rubocop:disable Lint/EmptyBlock
|
|
110
115
|
end
|
|
111
116
|
end
|
|
117
|
+
end
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'creates a new Provider object for the specified provider' do
|
|
125
|
-
expect(ItemsProvider).to receive(:new).with(external_provider)
|
|
126
|
-
config.items(external_provider)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it 'calls items on the provider object' do
|
|
130
|
-
expect(items_provider).to receive(:items)
|
|
131
|
-
config.items(external_provider)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it 'sets the items on the container' do
|
|
135
|
-
expect(container).to receive(:items=).with(items)
|
|
136
|
-
config.items(external_provider)
|
|
137
|
-
end
|
|
119
|
+
context 'when no block is given' do
|
|
120
|
+
context 'when items_provider is specified' do
|
|
121
|
+
let(:external_provider) { double(:external_provider) }
|
|
122
|
+
let(:items) { double(:items) }
|
|
123
|
+
let(:items_provider) { double(:items_provider, items: items) }
|
|
124
|
+
|
|
125
|
+
before do
|
|
126
|
+
allow(SimpleNavigation::ItemsProvider).to receive_messages(new: items_provider)
|
|
127
|
+
allow(container).to receive(:items=)
|
|
138
128
|
end
|
|
139
129
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
end
|
|
130
|
+
it 'creates a new Provider object for the specified provider' do
|
|
131
|
+
expect(SimpleNavigation::ItemsProvider).to receive(:new).with(external_provider)
|
|
132
|
+
config.items(external_provider)
|
|
144
133
|
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
134
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
135
|
+
it 'calls items on the provider object' do
|
|
136
|
+
expect(items_provider).to receive(:items)
|
|
137
|
+
config.items(external_provider)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'sets the items on the container' do
|
|
141
|
+
expect(container).to receive(:items=).with(items)
|
|
142
|
+
config.items(external_provider)
|
|
153
143
|
end
|
|
154
144
|
end
|
|
155
145
|
|
|
156
|
-
context 'when
|
|
157
|
-
it '
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
context 'when items_provider is not specified' do
|
|
147
|
+
it 'raises an exception' do
|
|
148
|
+
expect do
|
|
149
|
+
config.items
|
|
150
|
+
end.to raise_error(RuntimeError, 'please specify either items_provider or block, but not both')
|
|
160
151
|
end
|
|
161
152
|
end
|
|
162
153
|
end
|
|
163
154
|
end
|
|
155
|
+
|
|
156
|
+
describe '#loaded?' do
|
|
157
|
+
context 'when primary_nav is set' do
|
|
158
|
+
it 'returns true' do
|
|
159
|
+
config.instance_variable_set(:@primary_navigation, :bla)
|
|
160
|
+
expect(config).to be_loaded
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
context 'when primary_nav is not set' do
|
|
165
|
+
it 'returns false if no primary_nav is set' do
|
|
166
|
+
config.instance_variable_set(:@primary_navigation, nil)
|
|
167
|
+
expect(config).not_to be_loaded
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
164
171
|
end
|