simple-navigation-ext 0.0.1

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 +177 -0
  2. data/README +22 -0
  3. data/Rakefile +48 -0
  4. data/VERSION +1 -0
  5. data/generators/navigation_config/USAGE +1 -0
  6. data/generators/navigation_config/navigation_config_generator.rb +8 -0
  7. data/generators/navigation_config/templates/config/navigation.rb +67 -0
  8. data/lib/generators/navigation_config/navigation_config_generator.rb +12 -0
  9. data/lib/simple-navigation.rb +1 -0
  10. data/lib/simple_navigation/adapters/base.rb +37 -0
  11. data/lib/simple_navigation/adapters/padrino.rb +20 -0
  12. data/lib/simple_navigation/adapters/rails.rb +94 -0
  13. data/lib/simple_navigation/adapters/sinatra.rb +68 -0
  14. data/lib/simple_navigation/adapters.rb +9 -0
  15. data/lib/simple_navigation/core/configuration.rb +70 -0
  16. data/lib/simple_navigation/core/item.rb +117 -0
  17. data/lib/simple_navigation/core/item_adapter.rb +63 -0
  18. data/lib/simple_navigation/core/item_container.rb +146 -0
  19. data/lib/simple_navigation/core/items_provider.rb +35 -0
  20. data/lib/simple_navigation/core.rb +5 -0
  21. data/lib/simple_navigation/rails_controller_methods.rb +144 -0
  22. data/lib/simple_navigation/rendering/helpers.rb +82 -0
  23. data/lib/simple_navigation/rendering/renderer/base.rb +71 -0
  24. data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +37 -0
  25. data/lib/simple_navigation/rendering/renderer/links.rb +25 -0
  26. data/lib/simple_navigation/rendering/renderer/list.rb +47 -0
  27. data/lib/simple_navigation/rendering.rb +10 -0
  28. data/lib/simple_navigation.rb +162 -0
  29. data/rails/init.rb +1 -0
  30. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +29 -0
  31. data/spec/lib/simple_navigation/adapters/rails_spec.rb +284 -0
  32. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +60 -0
  33. data/spec/lib/simple_navigation/core/configuration_spec.rb +122 -0
  34. data/spec/lib/simple_navigation/core/item_adapter_spec.rb +209 -0
  35. data/spec/lib/simple_navigation/core/item_container_spec.rb +396 -0
  36. data/spec/lib/simple_navigation/core/item_spec.rb +513 -0
  37. data/spec/lib/simple_navigation/core/items_provider_spec.rb +60 -0
  38. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +249 -0
  39. data/spec/lib/simple_navigation/rendering/helpers_spec.rb +183 -0
  40. data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +199 -0
  41. data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +58 -0
  42. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +58 -0
  43. data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +189 -0
  44. data/spec/lib/simple_navigation_spec.rb +307 -0
  45. data/spec/spec_helper.rb +96 -0
  46. metadata +158 -0
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleNavigation::Configuration do
4
+
5
+ before(:each) do
6
+ @config = SimpleNavigation::Configuration.instance
7
+ end
8
+
9
+ describe 'self.run' do
10
+ it "should yield the singleton Configuration object" do
11
+ SimpleNavigation::Configuration.run do |c|
12
+ c.should == @config
13
+ end
14
+ end
15
+ end
16
+
17
+ describe 'self.eval_config' do
18
+ before(:each) do
19
+ @context = mock(:context)
20
+ @context.stub!(:instance_eval)
21
+ SimpleNavigation.stub!(:context_for_eval => @context)
22
+ @config_files = {:default => 'default', :my_context => 'my_context'}
23
+ SimpleNavigation.stub!(:config_files).and_return(@config_files)
24
+ end
25
+ context "with default navigation context" do
26
+ it "should instance_eval the default config_file-string inside the context" do
27
+ @context.should_receive(:instance_eval).with('default')
28
+ SimpleNavigation::Configuration.eval_config
29
+ end
30
+ end
31
+ context 'with non default navigation context' do
32
+ it "should instance_eval the specified config_file-string inside the context" do
33
+ @context.should_receive(:instance_eval).with('my_context')
34
+ SimpleNavigation::Configuration.eval_config(:my_context)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'initialize' do
40
+ it "should set the List-Renderer as default upon initialize" do
41
+ @config.renderer.should == SimpleNavigation::Renderer::List
42
+ end
43
+ it "should set the selected_class to 'selected' as default" do
44
+ @config.selected_class.should == 'selected'
45
+ end
46
+ it "should set autogenerate_item_ids to true as default" do
47
+ @config.autogenerate_item_ids.should be_true
48
+ end
49
+ it "should set auto_highlight to true as default" do
50
+ @config.auto_highlight.should be_true
51
+ end
52
+ it "should set the id_generator" do
53
+ @config.id_generator.should_not be_nil
54
+ end
55
+ end
56
+ describe 'items' do
57
+ before(:each) do
58
+ @container = stub(:items_container)
59
+ SimpleNavigation::ItemContainer.stub!(:new).and_return(@container)
60
+ end
61
+ context 'block given' do
62
+ context 'items_provider specified' do
63
+ it {lambda {@config.items(stub(:provider)) {}}.should raise_error}
64
+ end
65
+ context 'no items_provider specified' do
66
+ it "should should yield an new ItemContainer" do
67
+ @config.items do |container|
68
+ container.should == @container
69
+ end
70
+ end
71
+ it "should assign the ItemContainer to an instance-var" do
72
+ @config.items {}
73
+ @config.primary_navigation.should == @container
74
+ end
75
+ it "should not set the items on the container" do
76
+ @container.should_not_receive(:items=)
77
+ @config.items {}
78
+ end
79
+ end
80
+ end
81
+ context 'no block given' do
82
+ context 'items_provider specified' do
83
+ before(:each) do
84
+ @external_provider = stub(:external_provider)
85
+ @items = stub(:items)
86
+ @items_provider = stub(:items_provider, :items => @items)
87
+ SimpleNavigation::ItemsProvider.stub!(:new => @items_provider)
88
+ @container.stub!(:items=)
89
+ end
90
+ it "should create an new Provider object for the specified provider" do
91
+ SimpleNavigation::ItemsProvider.should_receive(:new).with(@external_provider)
92
+ @config.items(@external_provider)
93
+ end
94
+ it "should call items on the provider object" do
95
+ @items_provider.should_receive(:items)
96
+ @config.items(@external_provider)
97
+ end
98
+ it "should set the items on the container" do
99
+ @container.should_receive(:items=).with(@items)
100
+ @config.items(@external_provider)
101
+ end
102
+ end
103
+ context 'items_provider not specified' do
104
+ it {lambda {@config.items}.should raise_error}
105
+ end
106
+ end
107
+ end
108
+
109
+ describe 'loaded?' do
110
+ it "should return true if primary_nav is set" do
111
+ @config.instance_variable_set(:@primary_navigation, :bla)
112
+ @config.should be_loaded
113
+ end
114
+ it "should return false if no primary_nav is set" do
115
+ @config.instance_variable_set(:@primary_navigation, nil)
116
+ @config.should_not be_loaded
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+
@@ -0,0 +1,209 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleNavigation::ItemAdapter, 'when item is an object' do
4
+
5
+ before(:each) do
6
+ @item = stub(:item)
7
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
8
+ end
9
+
10
+ describe 'key' do
11
+ it "should delegate key to item" do
12
+ @item.should_receive(:key)
13
+ @item_adapter.key
14
+ end
15
+ end
16
+
17
+ describe 'url' do
18
+ it "should delegate url to item" do
19
+ @item.should_receive(:url)
20
+ @item_adapter.url
21
+ end
22
+ end
23
+
24
+ describe 'name' do
25
+ it "should delegate name to item" do
26
+ @item.should_receive(:name)
27
+ @item_adapter.name
28
+ end
29
+ end
30
+
31
+ describe 'initialize' do
32
+ it "should set the item" do
33
+ @item_adapter.item.should == @item
34
+ end
35
+ end
36
+
37
+ describe 'options' do
38
+ context 'item does respond to options' do
39
+ before(:each) do
40
+ @options = stub(:options)
41
+ @item.stub!(:options => @options)
42
+ end
43
+ it "should return the item's options'" do
44
+ @item_adapter.options.should == @options
45
+ end
46
+ end
47
+ context 'item does not respond to options' do
48
+ it "should return an empty hash" do
49
+ @item_adapter.options.should == {}
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'items' do
55
+ context 'item does respond to items' do
56
+ context 'items is nil' do
57
+ before(:each) do
58
+ @item.stub!(:items => nil)
59
+ end
60
+ it "should return nil" do
61
+ @item_adapter.items.should be_nil
62
+ end
63
+ end
64
+ context 'items is not nil' do
65
+ context 'items is empty' do
66
+ before(:each) do
67
+ @item.stub!(:items => [])
68
+ end
69
+ it "should return nil" do
70
+ @item_adapter.items.should be_nil
71
+ end
72
+ end
73
+ context 'items is not empty' do
74
+ before(:each) do
75
+ @items = stub(:items, :empty? => false)
76
+ @item.stub!(:items => @items)
77
+ end
78
+ it "should return the items" do
79
+ @item_adapter.items.should == @items
80
+ end
81
+ end
82
+ end
83
+ end
84
+ context 'item does not respond to items' do
85
+ it "should return nil" do
86
+ @item_adapter.items.should be_nil
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'to_simple_navigation_item' do
92
+ before(:each) do
93
+ @container = stub(:container)
94
+ @item.stub!(:url => 'url', :name => 'name', :key => 'key', :options => {}, :items => [])
95
+ end
96
+ it "should create a SimpleNavigation::Item" do
97
+ SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
98
+ @item_adapter.to_simple_navigation_item(@container)
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ describe SimpleNavigation::ItemAdapter, 'when item is a hash' do
105
+
106
+ before(:each) do
107
+ @item = {:key => 'key', :url => 'url', :name => 'name'}
108
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
109
+ end
110
+
111
+ describe 'key' do
112
+ it "should delegate key to item" do
113
+ @item_adapter.item.should_receive(:key)
114
+ @item_adapter.key
115
+ end
116
+ end
117
+
118
+ describe 'url' do
119
+ it "should delegate url to item" do
120
+ @item_adapter.item.should_receive(:url)
121
+ @item_adapter.url
122
+ end
123
+ end
124
+
125
+ describe 'name' do
126
+ it "should delegate name to item" do
127
+ @item_adapter.item.should_receive(:name)
128
+ @item_adapter.name
129
+ end
130
+ end
131
+
132
+ describe 'initialize' do
133
+ it "should set the item" do
134
+ @item_adapter.item.should_not be_nil
135
+ end
136
+ it "should have converted the item into an object" do
137
+ @item_adapter.item.should respond_to(:url)
138
+ end
139
+ end
140
+
141
+ describe 'options' do
142
+ context 'item does respond to options' do
143
+ before(:each) do
144
+ @item = {:key => 'key', :url => 'url', :name => 'name', :options => {:my => :options}}
145
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
146
+ end
147
+ it "should return the item's options'" do
148
+ @item_adapter.options.should == {:my => :options}
149
+ end
150
+ end
151
+ context 'item does not respond to options' do
152
+ it "should return an empty hash" do
153
+ @item_adapter.options.should == {}
154
+ end
155
+ end
156
+ end
157
+
158
+ describe 'items' do
159
+ context 'item does respond to items' do
160
+ context 'items is nil' do
161
+ before(:each) do
162
+ @item = {:key => 'key', :url => 'url', :name => 'name', :items => nil}
163
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
164
+ end
165
+ it "should return nil" do
166
+ @item_adapter.items.should be_nil
167
+ end
168
+ end
169
+ context 'items is not nil' do
170
+ context 'items is empty' do
171
+ before(:each) do
172
+ @item = {:key => 'key', :url => 'url', :name => 'name', :items => []}
173
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
174
+ end
175
+ it "should return nil" do
176
+ @item_adapter.items.should be_nil
177
+ end
178
+ end
179
+ context 'items is not empty' do
180
+ before(:each) do
181
+ @item = {:key => 'key', :url => 'url', :name => 'name', :items => ['not', 'empty']}
182
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
183
+ end
184
+ it "should return the items" do
185
+ @item_adapter.items.should == ['not', 'empty']
186
+ end
187
+ end
188
+ end
189
+ end
190
+ context 'item does not respond to items' do
191
+ it "should return nil" do
192
+ @item_adapter.items.should be_nil
193
+ end
194
+ end
195
+ end
196
+
197
+ describe 'to_simple_navigation_item' do
198
+ before(:each) do
199
+ @container = stub(:container)
200
+ @item = {:key => 'key', :url => 'url', :name => 'name', :items => [], :options => {}}
201
+ @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
202
+ end
203
+ it "should create a SimpleNavigation::Item" do
204
+ SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
205
+ @item_adapter.to_simple_navigation_item(@container)
206
+ end
207
+ end
208
+
209
+ end