nav_lynx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +25 -0
  3. data/Rakefile +22 -0
  4. data/app/helpers/nav_link_helper.rb +128 -0
  5. data/lib/nav_lynx.rb +4 -0
  6. data/lib/nav_lynx/engine.rb +7 -0
  7. data/lib/nav_lynx/version.rb +3 -0
  8. data/spec/dummy/README.rdoc +261 -0
  9. data/spec/dummy/Rakefile +7 -0
  10. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  13. data/spec/dummy/app/controllers/dashboard_controller.rb +3 -0
  14. data/spec/dummy/app/controllers/projects_controller.rb +2 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/views/dashboard/show.html.erb +1 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/spec/dummy/config.ru +4 -0
  19. data/spec/dummy/config/application.rb +65 -0
  20. data/spec/dummy/config/boot.rb +10 -0
  21. data/spec/dummy/config/database.yml +25 -0
  22. data/spec/dummy/config/environment.rb +5 -0
  23. data/spec/dummy/config/environments/development.rb +37 -0
  24. data/spec/dummy/config/environments/production.rb +67 -0
  25. data/spec/dummy/config/environments/test.rb +37 -0
  26. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/spec/dummy/config/initializers/inflections.rb +15 -0
  28. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  29. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  30. data/spec/dummy/config/initializers/session_store.rb +8 -0
  31. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/spec/dummy/config/locales/en.yml +5 -0
  33. data/spec/dummy/config/routes.rb +4 -0
  34. data/spec/dummy/db/development.sqlite3 +0 -0
  35. data/spec/dummy/db/schema.rb +16 -0
  36. data/spec/dummy/db/test.sqlite3 +0 -0
  37. data/spec/dummy/log/development.log +42 -0
  38. data/spec/dummy/log/test.log +263 -0
  39. data/spec/dummy/public/404.html +26 -0
  40. data/spec/dummy/public/422.html +26 -0
  41. data/spec/dummy/public/500.html +25 -0
  42. data/spec/dummy/public/favicon.ico +0 -0
  43. data/spec/dummy/script/rails +6 -0
  44. data/spec/features/navigation_spec.rb +9 -0
  45. data/spec/helpers/nav_link_helper_spec.rb +128 -0
  46. data/spec/spec_helper.rb +29 -0
  47. metadata +204 -0
@@ -0,0 +1,263 @@
1
+ Connecting to database specified by database.yml
2
+  (0.8ms) begin transaction
3
+  (0.1ms) rollback transaction
4
+  (0.1ms) begin transaction
5
+  (0.0ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+  (0.1ms) rollback transaction
8
+  (0.1ms) begin transaction
9
+  (0.1ms) rollback transaction
10
+  (0.1ms) begin transaction
11
+  (0.1ms) rollback transaction
12
+  (0.1ms) begin transaction
13
+  (0.1ms) rollback transaction
14
+  (0.1ms) begin transaction
15
+  (0.0ms) rollback transaction
16
+  (0.1ms) begin transaction
17
+  (0.1ms) rollback transaction
18
+  (0.1ms) begin transaction
19
+  (0.1ms) rollback transaction
20
+  (0.1ms) begin transaction
21
+  (0.1ms) rollback transaction
22
+  (0.1ms) begin transaction
23
+  (0.1ms) rollback transaction
24
+  (0.1ms) begin transaction
25
+  (0.0ms) rollback transaction
26
+  (0.1ms) begin transaction
27
+  (0.1ms) rollback transaction
28
+  (0.1ms) begin transaction
29
+  (0.1ms) rollback transaction
30
+  (0.1ms) begin transaction
31
+  (0.1ms) rollback transaction
32
+  (0.1ms) begin transaction
33
+  (0.1ms) rollback transaction
34
+  (0.1ms) begin transaction
35
+  (0.1ms) rollback transaction
36
+ Connecting to database specified by database.yml
37
+  (0.7ms) begin transaction
38
+  (0.1ms) rollback transaction
39
+  (0.1ms) begin transaction
40
+  (0.1ms) rollback transaction
41
+  (0.1ms) begin transaction
42
+  (0.1ms) rollback transaction
43
+  (0.1ms) begin transaction
44
+  (0.1ms) rollback transaction
45
+  (0.1ms) begin transaction
46
+  (0.1ms) rollback transaction
47
+  (0.1ms) begin transaction
48
+  (0.1ms) rollback transaction
49
+  (0.1ms) begin transaction
50
+  (0.1ms) rollback transaction
51
+  (0.1ms) begin transaction
52
+  (0.2ms) rollback transaction
53
+  (0.1ms) begin transaction
54
+  (0.1ms) rollback transaction
55
+  (0.1ms) begin transaction
56
+  (0.1ms) rollback transaction
57
+  (0.1ms) begin transaction
58
+  (0.1ms) rollback transaction
59
+  (0.1ms) begin transaction
60
+  (0.1ms) rollback transaction
61
+  (0.1ms) begin transaction
62
+  (0.1ms) rollback transaction
63
+  (0.1ms) begin transaction
64
+  (0.2ms) rollback transaction
65
+  (0.2ms) begin transaction
66
+  (0.1ms) rollback transaction
67
+  (0.1ms) begin transaction
68
+  (0.1ms) rollback transaction
69
+  (0.1ms) begin transaction
70
+  (0.1ms) rollback transaction
71
+ Connecting to database specified by database.yml
72
+  (0.7ms) begin transaction
73
+  (0.1ms) rollback transaction
74
+  (0.1ms) begin transaction
75
+  (0.2ms) rollback transaction
76
+  (0.1ms) begin transaction
77
+  (0.1ms) rollback transaction
78
+  (0.1ms) begin transaction
79
+  (0.1ms) rollback transaction
80
+  (0.1ms) begin transaction
81
+  (0.1ms) rollback transaction
82
+  (0.1ms) begin transaction
83
+  (0.1ms) rollback transaction
84
+  (0.1ms) begin transaction
85
+  (0.1ms) rollback transaction
86
+  (0.1ms) begin transaction
87
+  (0.1ms) rollback transaction
88
+  (0.2ms) begin transaction
89
+  (0.1ms) rollback transaction
90
+  (0.1ms) begin transaction
91
+  (0.1ms) rollback transaction
92
+  (0.1ms) begin transaction
93
+  (0.1ms) rollback transaction
94
+  (0.1ms) begin transaction
95
+  (0.1ms) rollback transaction
96
+  (0.1ms) begin transaction
97
+  (0.2ms) rollback transaction
98
+  (0.1ms) begin transaction
99
+  (0.1ms) rollback transaction
100
+  (0.1ms) begin transaction
101
+  (0.1ms) rollback transaction
102
+  (0.1ms) begin transaction
103
+  (0.1ms) rollback transaction
104
+  (0.1ms) begin transaction
105
+  (0.1ms) rollback transaction
106
+ Connecting to database specified by database.yml
107
+  (0.8ms) begin transaction
108
+  (0.1ms) rollback transaction
109
+  (0.1ms) begin transaction
110
+  (0.1ms) rollback transaction
111
+  (0.1ms) begin transaction
112
+  (0.1ms) rollback transaction
113
+  (0.1ms) begin transaction
114
+  (0.2ms) rollback transaction
115
+  (0.1ms) begin transaction
116
+  (0.1ms) rollback transaction
117
+  (0.1ms) begin transaction
118
+  (0.1ms) rollback transaction
119
+  (0.1ms) begin transaction
120
+  (0.1ms) rollback transaction
121
+  (0.1ms) begin transaction
122
+  (0.1ms) rollback transaction
123
+  (0.1ms) begin transaction
124
+  (0.2ms) rollback transaction
125
+  (0.1ms) begin transaction
126
+  (0.1ms) rollback transaction
127
+  (0.1ms) begin transaction
128
+  (0.1ms) rollback transaction
129
+  (0.1ms) begin transaction
130
+  (0.1ms) rollback transaction
131
+  (0.1ms) begin transaction
132
+  (0.1ms) rollback transaction
133
+  (0.1ms) begin transaction
134
+  (0.1ms) rollback transaction
135
+  (0.1ms) begin transaction
136
+  (0.2ms) rollback transaction
137
+  (0.1ms) begin transaction
138
+  (0.1ms) rollback transaction
139
+  (0.1ms) begin transaction
140
+  (0.1ms) rollback transaction
141
+ Connecting to database specified by database.yml
142
+  (0.8ms) begin transaction
143
+ Started GET "/" for 127.0.0.1 at 2013-06-12 14:43:53 -0600
144
+ Processing by DashboardController#show as HTML
145
+ Rendered dashboard/show.html.erb within layouts/application (15.2ms)
146
+ Completed 500 Internal Server Error in 49ms
147
+  (0.1ms) rollback transaction
148
+  (0.1ms) begin transaction
149
+  (0.1ms) rollback transaction
150
+  (0.1ms) begin transaction
151
+  (0.1ms) rollback transaction
152
+  (0.1ms) begin transaction
153
+  (0.2ms) rollback transaction
154
+  (0.1ms) begin transaction
155
+  (0.1ms) rollback transaction
156
+  (0.1ms) begin transaction
157
+  (0.1ms) rollback transaction
158
+  (0.1ms) begin transaction
159
+  (0.1ms) rollback transaction
160
+  (0.1ms) begin transaction
161
+  (0.1ms) rollback transaction
162
+  (0.1ms) begin transaction
163
+  (0.2ms) rollback transaction
164
+  (0.1ms) begin transaction
165
+  (0.1ms) rollback transaction
166
+  (0.1ms) begin transaction
167
+  (0.1ms) rollback transaction
168
+  (0.1ms) begin transaction
169
+  (0.1ms) rollback transaction
170
+  (0.1ms) begin transaction
171
+  (0.2ms) rollback transaction
172
+  (0.1ms) begin transaction
173
+  (0.1ms) rollback transaction
174
+  (0.1ms) begin transaction
175
+  (0.1ms) rollback transaction
176
+  (0.1ms) begin transaction
177
+  (0.1ms) rollback transaction
178
+  (0.1ms) begin transaction
179
+  (0.1ms) rollback transaction
180
+  (0.1ms) begin transaction
181
+  (0.1ms) rollback transaction
182
+ Connecting to database specified by database.yml
183
+  (0.9ms) begin transaction
184
+ Started GET "/" for 127.0.0.1 at 2013-06-12 14:44:12 -0600
185
+ Processing by DashboardController#show as HTML
186
+ Rendered dashboard/show.html.erb within layouts/application (7.6ms)
187
+ Completed 200 OK in 23ms (Views: 22.3ms | ActiveRecord: 0.0ms)
188
+  (0.1ms) rollback transaction
189
+  (0.1ms) begin transaction
190
+  (0.1ms) rollback transaction
191
+  (0.1ms) begin transaction
192
+  (0.1ms) rollback transaction
193
+  (0.1ms) begin transaction
194
+  (0.1ms) rollback transaction
195
+  (0.1ms) begin transaction
196
+  (0.1ms) rollback transaction
197
+  (0.1ms) begin transaction
198
+  (0.1ms) rollback transaction
199
+  (0.1ms) begin transaction
200
+  (0.1ms) rollback transaction
201
+  (0.1ms) begin transaction
202
+  (0.1ms) rollback transaction
203
+  (0.1ms) begin transaction
204
+  (0.1ms) rollback transaction
205
+  (0.1ms) begin transaction
206
+  (0.1ms) rollback transaction
207
+  (0.1ms) begin transaction
208
+  (0.1ms) rollback transaction
209
+  (0.1ms) begin transaction
210
+  (0.1ms) rollback transaction
211
+  (0.1ms) begin transaction
212
+  (0.1ms) rollback transaction
213
+  (0.1ms) begin transaction
214
+  (0.1ms) rollback transaction
215
+  (0.1ms) begin transaction
216
+  (0.1ms) rollback transaction
217
+  (0.1ms) begin transaction
218
+  (0.2ms) rollback transaction
219
+  (0.2ms) begin transaction
220
+  (0.1ms) rollback transaction
221
+  (0.1ms) begin transaction
222
+  (0.1ms) rollback transaction
223
+ Connecting to database specified by database.yml
224
+  (0.9ms) begin transaction
225
+ Started GET "/" for 127.0.0.1 at 2013-06-12 14:48:40 -0600
226
+ Processing by DashboardController#show as HTML
227
+ Rendered dashboard/show.html.erb within layouts/application (6.8ms)
228
+ Completed 200 OK in 21ms (Views: 20.3ms | ActiveRecord: 0.0ms)
229
+  (0.1ms) rollback transaction
230
+  (0.1ms) begin transaction
231
+  (0.1ms) rollback transaction
232
+  (0.1ms) begin transaction
233
+  (0.1ms) rollback transaction
234
+  (0.1ms) begin transaction
235
+  (0.1ms) rollback transaction
236
+  (0.1ms) begin transaction
237
+  (0.1ms) rollback transaction
238
+  (0.1ms) begin transaction
239
+  (0.1ms) rollback transaction
240
+  (0.1ms) begin transaction
241
+  (0.1ms) rollback transaction
242
+  (0.1ms) begin transaction
243
+  (0.1ms) rollback transaction
244
+  (0.1ms) begin transaction
245
+  (0.1ms) rollback transaction
246
+  (0.1ms) begin transaction
247
+  (0.1ms) rollback transaction
248
+  (0.1ms) begin transaction
249
+  (0.1ms) rollback transaction
250
+  (0.2ms) begin transaction
251
+  (0.1ms) rollback transaction
252
+  (0.1ms) begin transaction
253
+  (0.2ms) rollback transaction
254
+  (0.2ms) begin transaction
255
+  (0.1ms) rollback transaction
256
+  (0.1ms) begin transaction
257
+  (0.1ms) rollback transaction
258
+  (0.1ms) begin transaction
259
+  (0.1ms) rollback transaction
260
+  (0.1ms) begin transaction
261
+  (0.2ms) rollback transaction
262
+  (0.1ms) begin transaction
263
+  (0.2ms) rollback transaction
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rendering navigation links" do
4
+ it "renders the link correctly" do
5
+ visit '/'
6
+
7
+ page.should have_link("My Title", :href => "/projects")
8
+ end
9
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe NavLinkHelper do
4
+ describe '#nav_link' do
5
+ let(:link_generator) do
6
+ lg = double("LinkGenerator")
7
+ lg.stub(:to_html => true)
8
+ lg
9
+ end
10
+
11
+ before { helper.stub(:request => :request) }
12
+
13
+ it 'accepts only a title and a path' do
14
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
15
+ .and_return(link_generator)
16
+
17
+ helper.nav_link_to("My Title", "/path")
18
+ end
19
+
20
+ it 'accepts a block that returns the title' do
21
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", {}, {})
22
+ .and_return(link_generator)
23
+
24
+ helper.nav_link_to("/path") do
25
+ "My Title"
26
+ end
27
+ end
28
+
29
+ it "accepts options and html_options parameters" do
30
+ NavLinkHelper::LinkGenerator.should_receive(:new).with(:request, "My Title", "/path", :html_options, :options)
31
+ .and_return(link_generator)
32
+
33
+ helper.nav_link_to("My Title", "/path", :html_options, :options)
34
+ end
35
+ end
36
+
37
+ require 'spec_helper'
38
+
39
+ describe NavLinkHelper::LinkGenerator do
40
+ describe '#to_html' do
41
+ subject { described_class::LinkGenerator }
42
+ let(:request){ helper.request }
43
+
44
+ it "outputs a simple link when appropriate" do
45
+ subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
46
+ end
47
+
48
+ it "knows when to flag the link as current" do
49
+ request.stub(:fullpath).and_return('/projects')
50
+ subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects" class="selected">Hi</a>'
51
+ end
52
+
53
+ it "does not flag the link as current if there are parameters in the path" do
54
+ request.stub(:fullpath).and_return('/projects?all=true')
55
+ subject.new(request, 'Hi', '/projects').to_html.should == '<a href="/projects">Hi</a>'
56
+ end
57
+
58
+ it "flags the link as selected if there are parameters in the path but we are ignoring parameters" do
59
+ request.stub(:fullpath).and_return('/projects?all=true')
60
+ subject.new(request, 'Hi', '/projects', {}, :ignore_params => true).to_html
61
+ .should == '<a href="/projects" class="selected">Hi</a>'
62
+ end
63
+
64
+ it "allows the specification of an alternate selected class" do
65
+ request.stub(:fullpath).and_return('/projects')
66
+ subject.new(request, 'Hi', '/projects', {}, :selected_class => 'current').to_html
67
+ .should == '<a href="/projects" class="current">Hi</a>'
68
+ end
69
+
70
+ it "generates a wrapper for the link when specified" do
71
+ subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li').to_html
72
+ .should == '<li><a href="/projects">Hi</a></li>'
73
+ end
74
+
75
+ it "provides a class for the wrapper when specified" do
76
+ subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
77
+ .should == '<li class="container"><a href="/projects">Hi</a></li>'
78
+ end
79
+
80
+ it "provides a class for the wrapper when specified along with a selected class if neeeded" do
81
+ request.stub(:fullpath).and_return('/projects')
82
+ subject.new(request, 'Hi', '/projects', {}, :wrapper => 'li', :wrapper_class => 'container').to_html
83
+ .should == '<li class="selected container"><a href="/projects">Hi</a></li>'
84
+ end
85
+
86
+ it "allows specification of the link classes" do
87
+ subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
88
+ .should == '<a href="/projects" class="one two">Hi</a>'
89
+ end
90
+
91
+ it "combines custom link classes when the link is selected" do
92
+ request.stub(:fullpath).and_return('/projects')
93
+ subject.new(request, 'Hi', '/projects', :class => 'one two').to_html
94
+ .should == '<a href="/projects" class="one two selected">Hi</a>'
95
+ end
96
+
97
+ it "ignores the ID in the path when provided with a segment" do
98
+ request.stub(:fullpath).and_return('/projects/2')
99
+ subject.new(request, 'Hi', '/projects', {}, :url_segment => 1).to_html
100
+ .should == '<a href="/projects" class="selected">Hi</a>'
101
+ end
102
+
103
+ it "handles deep URL segments" do
104
+ request.stub(:fullpath).and_return('/projects/2/3')
105
+ subject.new(request, 'Hi', '/projects/2', {}, :url_segment => 2).to_html
106
+ .should == '<a href="/projects/2" class="selected">Hi</a>'
107
+ end
108
+
109
+ it "knows to not match on the first segment when requested" do
110
+ request.stub(:fullpath).and_return('/projects/2/3')
111
+ subject.new(request, 'Hi', '/projects/1', {}, :url_segment => 2).to_html
112
+ .should == '<a href="/projects/1">Hi</a>'
113
+ end
114
+
115
+ it "handles matching on the controller segment" do
116
+ Rails.application.routes.stub(:recognize_path).with('/members/1').and_return(:controller => 'members')
117
+ Rails.application.routes.stub(:recognize_path).with('/members/pages/1').and_return(:controller => 'members')
118
+
119
+ request.stub(:fullpath).and_return('/members/pages/1')
120
+ request.stub(:path).and_return('/members/pages/1')
121
+
122
+ subject.new(request, 'Hi', '/members/1', {}, :controller_segment => 1).to_html
123
+ .should == '<a href="/members/1" class="selected">Hi</a>'
124
+ end
125
+ end
126
+ end
127
+ end
128
+