simple-navigation 2.7.3 → 3.0.0.beta1

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 (46) hide show
  1. data/CHANGELOG +14 -4
  2. data/README +1 -2
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +4 -4
  5. data/generators/navigation_config/templates/config/navigation.rb +14 -14
  6. data/lib/simple_navigation.rb +69 -151
  7. data/lib/simple_navigation/adapters.rb +9 -0
  8. data/lib/simple_navigation/adapters/base.rb +37 -0
  9. data/lib/simple_navigation/adapters/padrino.rb +20 -0
  10. data/lib/simple_navigation/adapters/rails.rb +93 -0
  11. data/lib/simple_navigation/adapters/sinatra.rb +76 -0
  12. data/lib/simple_navigation/core.rb +5 -0
  13. data/lib/simple_navigation/{configuration.rb → core/configuration.rb} +14 -19
  14. data/lib/simple_navigation/{item.rb → core/item.rb} +10 -11
  15. data/lib/simple_navigation/{item_adapter.rb → core/item_adapter.rb} +11 -7
  16. data/lib/simple_navigation/{item_container.rb → core/item_container.rb} +14 -21
  17. data/lib/simple_navigation/{items_provider.rb → core/items_provider.rb} +7 -7
  18. data/lib/simple_navigation/{controller_methods.rb → rails_controller_methods.rb} +67 -5
  19. data/lib/simple_navigation/rendering.rb +10 -0
  20. data/lib/simple_navigation/{helpers.rb → rendering/helpers.rb} +16 -18
  21. data/lib/simple_navigation/{renderer → rendering/renderer}/base.rb +20 -37
  22. data/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs.rb +7 -7
  23. data/lib/simple_navigation/{renderer → rendering/renderer}/links.rb +7 -7
  24. data/lib/simple_navigation/{renderer → rendering/renderer}/list.rb +6 -6
  25. data/rails/init.rb +1 -5
  26. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +29 -0
  27. data/spec/lib/simple_navigation/adapters/rails_spec.rb +269 -0
  28. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +60 -0
  29. data/spec/lib/simple_navigation/{configuration_spec.rb → core/configuration_spec.rb} +7 -18
  30. data/spec/lib/simple_navigation/{item_adapter_spec.rb → core/item_adapter_spec.rb} +11 -11
  31. data/spec/lib/simple_navigation/{item_container_spec.rb → core/item_container_spec.rb} +29 -46
  32. data/spec/lib/simple_navigation/{item_spec.rb → core/item_spec.rb} +30 -64
  33. data/spec/lib/simple_navigation/{items_provider_spec.rb → core/items_provider_spec.rb} +7 -7
  34. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +251 -0
  35. data/spec/lib/simple_navigation/{helpers_spec.rb → rendering/helpers_spec.rb} +34 -53
  36. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/base_spec.rb +11 -62
  37. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/breadcrumbs_spec.rb +9 -51
  38. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +59 -0
  39. data/spec/lib/simple_navigation/{renderer → rendering/renderer}/list_spec.rb +17 -58
  40. data/spec/lib/simple_navigation_spec.rb +51 -298
  41. data/spec/spec_helper.rb +16 -5
  42. metadata +67 -48
  43. data/lib/simple_navigation/initializer.rb +0 -21
  44. data/lib/simple_navigation/railtie.rb +0 -7
  45. data/spec/lib/simple_navigation/controller_methods_spec.rb +0 -90
  46. data/spec/lib/simple_navigation/renderer/links_spec.rb +0 -121
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
- describe SimpleNavigation::ItemContainer do
3
+ describe SimpleNavigation::ItemContainer do
4
4
  before(:each) do
5
5
  @item_container = SimpleNavigation::ItemContainer.new
6
6
  end
@@ -74,22 +74,12 @@ describe SimpleNavigation::ItemContainer do
74
74
 
75
75
  describe 'selected_item' do
76
76
  before(:each) do
77
+ @item_container.stub!(:[] => nil)
77
78
  @item_1 = stub(:item, :selected? => false)
78
79
  @item_2 = stub(:item, :selected? => false)
79
80
  @item_container.instance_variable_set(:@items, [@item_1, @item_2])
80
81
  end
81
- context 'navigation explicitely set' do
82
- before(:each) do
83
- @item_container.stub!(:[] => @item_1)
84
- end
85
- it "should return the explicitely selected item" do
86
- @item_container.selected_item.should == @item_1
87
- end
88
- end
89
82
  context 'navigation not explicitely set' do
90
- before(:each) do
91
- @item_container.stub!(:[] => nil)
92
- end
93
83
  context 'no item selected' do
94
84
  it "should return nil" do
95
85
  @item_container.selected_item.should be_nil
@@ -162,28 +152,21 @@ describe SimpleNavigation::ItemContainer do
162
152
  end
163
153
  end
164
154
 
165
- describe 'current_explicit_navigation' do
166
- it "should call SimpleNavigation.current_navigation with the container's level" do
167
- SimpleNavigation.should_receive(:current_navigation_for).with(1)
168
- @item_container.current_explicit_navigation
169
- end
170
- end
171
-
172
155
  describe 'item' do
173
-
156
+
174
157
  context 'unconditional item' do
175
-
158
+
176
159
  before(:each) do
177
160
  @item_container.stub!(:should_add_item?).and_return(true)
178
161
  @options = {}
179
162
  end
180
-
181
- context 'block given' do
163
+
164
+ context 'block given' do
182
165
  before(:each) do
183
166
  @sub_container = stub(:sub_container)
184
167
  SimpleNavigation::ItemContainer.stub!(:new).and_return(@sub_container)
185
168
  end
186
-
169
+
187
170
  it "should should yield an new ItemContainer" do
188
171
  @item_container.item('key', 'name', 'url', @options) do |container|
189
172
  container.should == @sub_container
@@ -198,7 +181,7 @@ describe SimpleNavigation::ItemContainer do
198
181
  @item_container.item('key', 'name', 'url', @options) {}
199
182
  end
200
183
  end
201
-
184
+
202
185
  context 'no block given' do
203
186
  it "should create a new Navigation_item with the given params and nil as sub_navi" do
204
187
  SimpleNavigation::Item.should_receive(:new).with(@item_container, 'key', 'name', 'url', @options, nil)
@@ -211,20 +194,20 @@ describe SimpleNavigation::ItemContainer do
211
194
  end
212
195
 
213
196
  end
214
-
197
+
215
198
  context 'conditions given for item' do
216
-
199
+
217
200
  context '"if" given' do
218
201
 
219
202
  before(:each) do
220
203
  @options = {:if => Proc.new {@condition}}
221
204
  end
222
-
205
+
223
206
  it "should remove if from options" do
224
207
  @item_container.item('key', 'name', 'url', @options)
225
208
  @options[:if].should be_nil
226
209
  end
227
-
210
+
228
211
  context 'if evals to true' do
229
212
  before(:each) do
230
213
  @condition = true
@@ -234,7 +217,7 @@ describe SimpleNavigation::ItemContainer do
234
217
  @item_container.item('key', 'name', 'url', @options)
235
218
  end
236
219
  end
237
-
220
+
238
221
  context 'if evals to false' do
239
222
  before(:each) do
240
223
  @condition = false
@@ -244,7 +227,7 @@ describe SimpleNavigation::ItemContainer do
244
227
  @item_container.item('key', 'name', 'url', @options)
245
228
  end
246
229
  end
247
-
230
+
248
231
  context 'if is not a proc or method' do
249
232
  it "should raise an error" do
250
233
  lambda {@item_container.item('key', 'name', 'url', {:if => 'text'})}.should raise_error
@@ -252,17 +235,17 @@ describe SimpleNavigation::ItemContainer do
252
235
  end
253
236
 
254
237
  context '"unless" given' do
255
-
238
+
256
239
  before(:each) do
257
240
  @options = {:unless => Proc.new {@condition}}
258
241
  end
259
-
260
-
242
+
243
+
261
244
  it "should remove unless from options" do
262
245
  @item_container.item('key', 'name', 'url', @options)
263
246
  @options[:unless].should be_nil
264
247
  end
265
-
248
+
266
249
  context 'unless evals to false' do
267
250
  before(:each) do
268
251
  @condition = false
@@ -282,20 +265,20 @@ describe SimpleNavigation::ItemContainer do
282
265
  @item_container.item('key', 'name', 'url', @options)
283
266
  end
284
267
  end
285
-
268
+
286
269
  end
287
270
  end
288
271
  end
289
272
  end
290
-
273
+
291
274
  describe '[]' do
292
-
275
+
293
276
  before(:each) do
294
277
  @item_container.item(:first, 'first', 'bla')
295
278
  @item_container.item(:second, 'second', 'bla')
296
279
  @item_container.item(:third, 'third', 'bla')
297
280
  end
298
-
281
+
299
282
  it "should return the item with the specified navi_key" do
300
283
  @item_container[:second].name.should == 'second'
301
284
  end
@@ -303,7 +286,7 @@ describe SimpleNavigation::ItemContainer do
303
286
  @item_container[:invalid].should be_nil
304
287
  end
305
288
  end
306
-
289
+
307
290
  describe 'render' do
308
291
  before(:each) do
309
292
  @renderer_instance = stub(:renderer, :null_object => true)
@@ -316,7 +299,7 @@ describe SimpleNavigation::ItemContainer do
316
299
  end
317
300
  it "should call render on the renderer and pass self" do
318
301
  @renderer_instance.should_receive(:render).with(@item_container)
319
- end
302
+ end
320
303
  after(:each) do
321
304
  @item_container.render(:renderer => @renderer_class)
322
305
  end
@@ -330,10 +313,10 @@ describe SimpleNavigation::ItemContainer do
330
313
  end
331
314
  it "should call render on the renderer and pass self" do
332
315
  @renderer_instance.should_receive(:render).with(@item_container)
333
- end
316
+ end
334
317
  after(:each) do
335
318
  @item_container.render(:renderer => :my_renderer)
336
- end
319
+ end
337
320
  end
338
321
  end
339
322
  context 'no renderer specified' do
@@ -352,7 +335,7 @@ describe SimpleNavigation::ItemContainer do
352
335
  end
353
336
  end
354
337
  end
355
-
338
+
356
339
  describe 'level_for_item' do
357
340
  before(:each) do
358
341
  @item_container.item(:p1, 'p1', 'p1')
@@ -373,7 +356,7 @@ describe SimpleNavigation::ItemContainer do
373
356
  it {@item_container.level_for_item(:x).should be_nil}
374
357
 
375
358
  end
376
-
359
+
377
360
  describe 'empty?' do
378
361
  it "should be empty if there are no items" do
379
362
  @item_container.instance_variable_set(:@items, [])
@@ -1,10 +1,12 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Item do
4
4
 
5
5
  before(:each) do
6
6
  @item_container = stub(:item_container, :level => 1)
7
7
  @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
8
+ @adapter = stub(:adapter)
9
+ SimpleNavigation.stub!(:adapter => @adapter)
8
10
  end
9
11
 
10
12
  describe 'initialize' do
@@ -58,14 +60,14 @@ describe SimpleNavigation::Item do
58
60
  @item.instance_variable_get(:@html_options).key?(:method).should be_false
59
61
  end
60
62
  end
61
-
63
+
62
64
  context 'undefined' do
63
65
  it 'should set the instance-var to nil' do
64
66
  @item.method.should be_nil
65
67
  end
66
68
  end
67
69
  end
68
-
70
+
69
71
  context ':highlights_on option' do
70
72
  context 'defined' do
71
73
  before(:each) do
@@ -80,7 +82,7 @@ describe SimpleNavigation::Item do
80
82
  @item.instance_variable_get(:@html_options).key?(:highlights_on).should be_false
81
83
  end
82
84
  end
83
-
85
+
84
86
  context 'undefined' do
85
87
  it 'should set the instance-var to nil' do
86
88
  @item.highlights_on.should be_nil
@@ -88,7 +90,7 @@ describe SimpleNavigation::Item do
88
90
  end
89
91
  end
90
92
  end
91
-
93
+
92
94
  describe 'selected?' do
93
95
  context 'explicitly selected' do
94
96
  before(:each) do
@@ -130,7 +132,7 @@ describe SimpleNavigation::Item do
130
132
  end
131
133
  end
132
134
  end
133
-
135
+
134
136
  describe 'selected_class' do
135
137
  context 'item is selected' do
136
138
  before(:each) do
@@ -138,7 +140,7 @@ describe SimpleNavigation::Item do
138
140
  end
139
141
  it {@item.instance_eval {selected_class.should == 'selected'}}
140
142
  end
141
-
143
+
142
144
  context 'item is not selected' do
143
145
  before(:each) do
144
146
  @item.stub!(:selected? => false)
@@ -146,7 +148,7 @@ describe SimpleNavigation::Item do
146
148
  it {@item.instance_eval {selected_class.should == nil}}
147
149
  end
148
150
  end
149
-
151
+
150
152
  describe 'html_options' do
151
153
  describe 'class' do
152
154
  context 'with classes defined in options' do
@@ -160,7 +162,7 @@ describe SimpleNavigation::Item do
160
162
  end
161
163
  it {@item.html_options[:class].should == 'my_class selected'}
162
164
  end
163
-
165
+
164
166
  context 'with item not selected' do
165
167
  before(:each) do
166
168
  @item.stub!(:selected? => false)
@@ -168,7 +170,7 @@ describe SimpleNavigation::Item do
168
170
  it {@item.html_options[:class].should == 'my_class'}
169
171
  end
170
172
  end
171
-
173
+
172
174
  context 'without classes in options' do
173
175
  before(:each) do
174
176
  @options = {}
@@ -180,7 +182,7 @@ describe SimpleNavigation::Item do
180
182
  end
181
183
  it {@item.html_options[:class].should == 'selected'}
182
184
  end
183
-
185
+
184
186
  context 'with item not selected' do
185
187
  before(:each) do
186
188
  @item.stub!(:selected? => false)
@@ -189,7 +191,7 @@ describe SimpleNavigation::Item do
189
191
  end
190
192
  end
191
193
  end
192
-
194
+
193
195
  describe 'id' do
194
196
  context 'with autogenerate_item_ids == true' do
195
197
  before(:each) do
@@ -202,7 +204,7 @@ describe SimpleNavigation::Item do
202
204
  end
203
205
  it {@item.html_options[:id].should == 'my_id'}
204
206
  end
205
-
207
+
206
208
  context 'with no id defined in options (using default id)' do
207
209
  before(:each) do
208
210
  @item.html_options = {}
@@ -222,18 +224,18 @@ describe SimpleNavigation::Item do
222
224
  end
223
225
  it {@item.html_options[:id].should == 'my_id'}
224
226
  end
225
-
227
+
226
228
  context 'with no id definied in options (using default id)' do
227
229
  before(:each) do
228
230
  @item.html_options = {}
229
231
  end
230
232
  it {@item.html_options[:id].should be_nil}
231
233
  end
232
-
234
+
233
235
  end
234
236
 
235
237
  end
236
-
238
+
237
239
  end
238
240
 
239
241
  describe 'selected_by_subnav?' do
@@ -259,25 +261,6 @@ describe SimpleNavigation::Item do
259
261
  end
260
262
  end
261
263
 
262
- describe 'selected_by_config?' do
263
- context 'navigation explicitly set' do
264
- it "should return true if current matches key" do
265
- @item_container.stub!(:current_explicit_navigation => :my_key)
266
- @item.should be_selected_by_config
267
- end
268
- it "should return false if current does not match key" do
269
- @item_container.stub!(:current_explicit_navigation => :other_key)
270
- @item.should_not be_selected_by_config
271
- end
272
- end
273
- context 'navigation not explicitly set' do
274
- before(:each) do
275
- @item_container.stub!(:current_explicit_navigation => nil)
276
- end
277
- it {@item.should_not be_selected_by_config}
278
- end
279
- end
280
-
281
264
  describe 'selected_by_url?' do
282
265
  context ':highlights_on option is set' do
283
266
  before(:each) do
@@ -331,31 +314,19 @@ describe SimpleNavigation::Item do
331
314
  before(:each) do
332
315
  @item.stub!(:root_path_match? => false)
333
316
  end
334
- context 'template is set' do
317
+ context 'current request url matches url' do
335
318
  before(:each) do
336
- @template = stub(:template)
337
- SimpleNavigation.stub!(:template => @template)
338
- end
339
- context 'current request url matches url' do
340
- before(:each) do
341
- @template.stub!(:current_page? => true)
342
- end
343
- it "should test with the item's url" do
344
- @template.should_receive(:current_page?).with('url')
345
- @item.send(:selected_by_url?)
346
- end
347
- it {@item.send(:selected_by_url?).should be_true}
319
+ @adapter.stub!(:current_page? => true)
348
320
  end
349
- context 'no match' do
350
- before(:each) do
351
- @template.stub!(:current_page? => false)
352
- end
353
- it {@item.send(:selected_by_url?).should be_false}
321
+ it "should test with the item's url" do
322
+ @adapter.should_receive(:current_page?).with('url')
323
+ @item.send(:selected_by_url?)
354
324
  end
325
+ it {@item.send(:selected_by_url?).should be_true}
355
326
  end
356
- context 'template is not set' do
327
+ context 'no match' do
357
328
  before(:each) do
358
- SimpleNavigation.stub!(:template => nil)
329
+ @adapter.stub!(:current_page? => false)
359
330
  end
360
331
  it {@item.send(:selected_by_url?).should be_false}
361
332
  end
@@ -370,28 +341,23 @@ describe SimpleNavigation::Item do
370
341
  end
371
342
 
372
343
  describe 'root_path_match?' do
373
- before(:each) do
374
- @request = stub(:request)
375
- @controller = stub(:controller, :request => @request)
376
- SimpleNavigation.stub!(:controller => @controller)
377
- end
378
344
  it "should match if both url == /" do
379
- @request.stub!(:path => '/')
345
+ @adapter.stub!(:request_path => '/')
380
346
  @item.stub!(:url => '/')
381
347
  @item.send(:root_path_match?).should be_true
382
348
  end
383
349
  it "should not match if item url is not /" do
384
- @request.stub!(:path => '/')
350
+ @adapter.stub(:request_path => '/')
385
351
  @item.stub!(:url => '/bla')
386
352
  @item.send(:root_path_match?).should be_false
387
353
  end
388
354
  it "should not match if request url is not /" do
389
- @request.stub!(:path => '/bla')
355
+ @adapter.stub(:request_path => '/bla')
390
356
  @item.stub!(:url => '/')
391
357
  @item.send(:root_path_match?).should be_false
392
358
  end
393
359
  it "should not match if urls do not match" do
394
- @request.stub!(:path => '/bla')
360
+ @adapter.stub(:request_path => 'bla')
395
361
  @item.stub!(:url => '/bli')
396
362
  @item.send(:root_path_match?).should be_false
397
363
  end
@@ -1,18 +1,18 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
2
 
3
3
  describe SimpleNavigation::ItemsProvider do
4
-
4
+
5
5
  before(:each) do
6
6
  @provider = stub(:provider)
7
7
  @items_provider = SimpleNavigation::ItemsProvider.new(@provider)
8
8
  end
9
-
9
+
10
10
  describe 'initialize' do
11
11
  it "should set the provider" do
12
12
  @items_provider.provider.should == @provider
13
13
  end
14
14
  end
15
-
15
+
16
16
  describe 'items' do
17
17
  before(:each) do
18
18
  @items = stub(:items)
@@ -21,7 +21,7 @@ describe SimpleNavigation::ItemsProvider do
21
21
  before(:each) do
22
22
  @items_provider.instance_variable_set(:@provider, :provider_method)
23
23
  @context = stub(:context, :provider_method => @items)
24
- SimpleNavigation::Configuration.stub!(:context_for_eval => @context)
24
+ SimpleNavigation.stub!(:context_for_eval => @context)
25
25
  end
26
26
  it "should call the method specified by symbol on the context" do
27
27
  @context.should_receive(:provider_method)
@@ -46,7 +46,7 @@ describe SimpleNavigation::ItemsProvider do
46
46
  context 'provider is a collection' do
47
47
  before(:each) do
48
48
  @items_collection = []
49
- @items_provider.instance_variable_set(:@provider, @items_collection)
49
+ @items_provider.instance_variable_set(:@provider, @items_collection)
50
50
  end
51
51
  it "should return the collection itsself" do
52
52
  @items_provider.items.should == @items_collection
@@ -56,5 +56,5 @@ describe SimpleNavigation::ItemsProvider do
56
56
  it {lambda {@items_provider.items}.should raise_error}
57
57
  end
58
58
  end
59
-
59
+
60
60
  end