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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +84 -0
  3. data/.rspec +1 -2
  4. data/.rubocop.yml +49 -0
  5. data/.rubocop_todo.yml +38 -0
  6. data/Appraisals +55 -0
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +21 -0
  9. data/Guardfile +4 -2
  10. data/README.md +11 -23
  11. data/Rakefile +2 -27
  12. data/bin/_guard-core +16 -0
  13. data/bin/appraisal +16 -0
  14. data/bin/guard +16 -0
  15. data/bin/rake +16 -0
  16. data/bin/rspec +16 -0
  17. data/bin/rubocop +16 -0
  18. data/gemfiles/rails_6.1.gemfile +35 -0
  19. data/gemfiles/rails_7.0.gemfile +23 -0
  20. data/gemfiles/rails_7.1.gemfile +23 -0
  21. data/gemfiles/rails_7.2.gemfile +23 -0
  22. data/gemfiles/rails_8.0.gemfile +23 -0
  23. data/gemfiles/rails_8.1.gemfile +23 -0
  24. data/generators/navigation_config/navigation_config_generator.rb +2 -0
  25. data/generators/navigation_config/templates/config/navigation.rb +30 -26
  26. data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
  27. data/lib/simple-navigation.rb +3 -1
  28. data/lib/simple_navigation/adapters/base.rb +2 -0
  29. data/lib/simple_navigation/adapters/nanoc.rb +8 -3
  30. data/lib/simple_navigation/adapters/padrino.rb +3 -1
  31. data/lib/simple_navigation/adapters/rails.rb +12 -14
  32. data/lib/simple_navigation/adapters/sinatra.rb +4 -6
  33. data/lib/simple_navigation/config_file.rb +1 -1
  34. data/lib/simple_navigation/config_file_finder.rb +3 -3
  35. data/lib/simple_navigation/configuration.rb +5 -5
  36. data/lib/simple_navigation/helpers.rb +9 -11
  37. data/lib/simple_navigation/item.rb +26 -20
  38. data/lib/simple_navigation/item_adapter.rb +16 -5
  39. data/lib/simple_navigation/item_container.rb +13 -7
  40. data/lib/simple_navigation/items_provider.rb +6 -4
  41. data/lib/simple_navigation/railtie.rb +3 -1
  42. data/lib/simple_navigation/renderer/base.rb +5 -5
  43. data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
  44. data/lib/simple_navigation/renderer/json.rb +1 -1
  45. data/lib/simple_navigation/renderer/links.rb +2 -0
  46. data/lib/simple_navigation/renderer/list.rb +5 -5
  47. data/lib/simple_navigation/renderer/text.rb +3 -1
  48. data/lib/simple_navigation/version.rb +3 -1
  49. data/lib/simple_navigation.rb +32 -24
  50. data/simple-navigation.gemspec +16 -27
  51. data/spec/fake_app/config/navigation.rb +4 -2
  52. data/spec/fake_app/rails_app.rb +5 -3
  53. data/spec/integration/rendering_navigation_spec.rb +7 -5
  54. data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
  55. data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
  56. data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
  57. data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
  58. data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
  59. data/spec/simple_navigation/config_file_spec.rb +14 -14
  60. data/spec/simple_navigation/configuration_spec.rb +128 -121
  61. data/spec/simple_navigation/helpers_spec.rb +282 -284
  62. data/spec/simple_navigation/item_adapter_spec.rb +109 -122
  63. data/spec/simple_navigation/item_container_spec.rb +407 -408
  64. data/spec/simple_navigation/item_spec.rb +333 -301
  65. data/spec/simple_navigation/items_provider_spec.rb +30 -27
  66. data/spec/simple_navigation/renderer/base_spec.rb +166 -168
  67. data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
  68. data/spec/simple_navigation/renderer/json_spec.rb +49 -56
  69. data/spec/simple_navigation/renderer/links_spec.rb +81 -83
  70. data/spec/simple_navigation/renderer/list_spec.rb +111 -91
  71. data/spec/simple_navigation/renderer/text_spec.rb +37 -39
  72. data/spec/simple_navigation_spec.rb +54 -47
  73. data/spec/spec_helper.rb +146 -53
  74. metadata +25 -164
  75. data/.travis.yml +0 -23
  76. data/gemfiles/rails-3-2-stable.gemfile +0 -11
  77. data/gemfiles/rails-4-1-stable.gemfile +0 -7
  78. data/gemfiles/rails-4-2-stable.gemfile +0 -7
  79. data/gemfiles/rails-5-2-stable.gemfile +0 -7
  80. data/gemfiles/rails-6-0-stable.gemfile +0 -9
  81. data/gemfiles/rails-6-1-stable.gemfile +0 -9
  82. data/init.rb +0 -1
  83. data/install.rb +0 -5
  84. data/lib/simple_navigation/adapters.rb +0 -10
  85. data/lib/simple_navigation/renderer.rb +0 -12
  86. data/spec/initializers/coveralls.rb +0 -3
  87. data/spec/initializers/have_css_matcher.rb +0 -19
  88. data/spec/initializers/memfs.rb +0 -7
  89. data/spec/initializers/rails.rb +0 -4
  90. data/spec/initializers/rspec.rb +0 -7
  91. 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
- module SimpleNavigation
4
- describe ConfigFile do
5
- subject(:config_file) { ConfigFile.new(context) }
5
+ RSpec.describe SimpleNavigation::ConfigFile do
6
+ subject(:config_file) { described_class.new(context) }
6
7
 
7
- let(:context) { :default }
8
+ let(:context) { :default }
8
9
 
9
- describe '#name' do
10
- context 'when the context is :default' do
11
- it 'returns navigation.rb' do
12
- expect(config_file.name).to eq 'navigation.rb'
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
- context 'when the context is different from :default' do
17
- let(:context) { :HelloWorld }
17
+ context 'when the context is different from :default' do
18
+ let(:context) { :HelloWorld }
18
19
 
19
- it 'returns UNDERSCORED_CONTEXT_navigation.rb' do
20
- expect(config_file.name).to eq 'hello_world_navigation.rb'
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
- module SimpleNavigation
2
- describe Configuration do
3
- subject(:config) { Configuration.instance }
1
+ # frozen_string_literal: true
4
2
 
5
- describe '.run' do
6
- it "yields the singleton Configuration object" do
7
- expect{ |blk| Configuration.run(&blk) }.to yield_with_args(config)
8
- end
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
- describe '.eval_config' do
12
- let(:config_files) {{ default: 'default', my_context: 'my_context' }}
13
- let(:eval_context) { double(:eval_context) }
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
- before do
16
- allow(eval_context).to receive(:instance_eval)
17
- allow(SimpleNavigation).to \
18
- receive_messages(context_for_eval: eval_context, config_files: config_files)
19
- end
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
- context "with default navigation context" do
22
- it "calls instance_eval with the default config_file-string inside the context" do
23
- expect(eval_context).to receive(:instance_eval).with('default')
24
- Configuration.eval_config
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
- context 'with non default navigation context' do
29
- it "calls instance_eval with the specified config_file-string inside the context" do
30
- expect(eval_context).to receive(:instance_eval).with('my_context')
31
- Configuration.eval_config(:my_context)
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
- describe '#initialize' do
37
- it 'sets the List-Renderer as default' do
38
- expect(config.renderer).to be Renderer::List
39
- end
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
- it 'sets the selected_class to "selected" as default' do
42
- expect(config.selected_class).to eq 'selected'
43
- end
42
+ it 'sets the selected_class to "selected" as default' do
43
+ expect(config.selected_class).to eq 'selected'
44
+ end
44
45
 
45
- it 'sets the active_leaf_class to "simple-navigation-active-leaf" as default' do
46
- expect(config.active_leaf_class).to eq 'simple-navigation-active-leaf'
47
- end
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
- it 'sets autogenerate_item_ids to true as default' do
50
- expect(config.autogenerate_item_ids).to be true
51
- end
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
- it 'sets auto_highlight to true as default' do
54
- expect(config.auto_highlight).to be true
55
- end
54
+ it 'sets auto_highlight to true as default' do
55
+ expect(config.auto_highlight).to be true
56
+ end
56
57
 
57
- it 'sets the id_generator to a callable object' do
58
- expect(config.id_generator).to respond_to(:call)
59
- end
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
- it 'sets the name_generator to a callable object' do
62
- expect(config.name_generator).to respond_to(:call)
63
- end
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
- it 'sets the consider_item_names_as_safe to false' do
66
- expect(config.consider_item_names_as_safe).to be false
67
- end
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
- it 'sets highlights_on_subpath to false as default' do
70
- expect(config.highlight_on_subpath).to be false
71
- end
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
- it 'sets ignore_anchors_on_auto_highlight to true as default' do
78
- expect(config.ignore_anchors_on_auto_highlight).to be true
79
- end
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
- describe '#items' do
83
- let(:container) { double(:items_container) }
83
+ describe '#items' do
84
+ let(:container) { double(:items_container) }
84
85
 
85
- before { allow(ItemContainer).to receive_messages(new: container) }
86
+ before { allow(SimpleNavigation::ItemContainer).to receive_messages(new: container) }
86
87
 
87
- context 'when a block is given' do
88
- context 'and items_provider is specified' do
89
- let(:provider) { double(:provider) }
88
+ context 'when a block is given' do
89
+ context 'when items_provider is specified' do
90
+ let(:provider) { double(:provider) }
90
91
 
91
- it 'raises an exception' do
92
- expect{ config.items(provider) {} }.to raise_error(RuntimeError, 'please specify either items_provider or block, but not both')
93
- end
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
- context 'when no items_provider is specified' do
97
- it 'yields an new ItemContainer' do
98
- expect{ |blk| config.items(&blk) }.to yield_with_args(container)
99
- end
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
- it 'assigns the ItemContainer to an instance-var' do
102
- config.items {}
103
- expect(config.primary_navigation).to be container
104
- end
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
- it "doesn't set the items on the container" do
107
- expect(container).not_to receive(:items=)
108
- config.items {}
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
- context 'when no block is given' do
114
- context 'and items_provider is specified' do
115
- let(:external_provider) { double(:external_provider) }
116
- let(:items) { double(:items) }
117
- let(:items_provider) { double(:items_provider, items: items) }
118
-
119
- before do
120
- allow(SimpleNavigation::ItemsProvider).to receive_messages(new: items_provider)
121
- allow(container).to receive(:items=)
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
- context 'when items_provider is not specified' do
141
- it "raises an exception" do
142
- expect{ config.items }.to raise_error(RuntimeError, 'please specify either items_provider or block, but not both')
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
- describe '#loaded?' do
149
- context 'when primary_nav is set' do
150
- it 'returns true' do
151
- config.instance_variable_set(:@primary_navigation, :bla)
152
- expect(config).to be_loaded
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 primary_nav is not set' do
157
- it 'returns false if no primary_nav is set' do
158
- config.instance_variable_set(:@primary_navigation, nil)
159
- expect(config).not_to be_loaded
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