navi 0.1.4 → 0.2.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 (37) hide show
  1. data/.gitignore +1 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +3 -0
  4. data/Gemfile +6 -1
  5. data/Gemfile.lock +117 -134
  6. data/README.md +8 -0
  7. data/features/step_definitions/category_steps.rb +1 -1
  8. data/features/step_definitions/page_steps.rb +1 -1
  9. data/features/support/env.rb +7 -2
  10. data/lib/navi.rb +2 -1
  11. data/lib/navi/renderers/base.rb +12 -10
  12. data/lib/navi/renderers/simple_navigation.rb +6 -32
  13. data/lib/navi/renderers/simple_navigation/dynamic_item.rb +18 -0
  14. data/lib/navi/renderers/simple_navigation/dynamic_items.rb +26 -0
  15. data/lib/navi/renderers/simple_navigation/generates_uri.rb +32 -0
  16. data/lib/navi/renderers/simple_navigation/renderer.rb +27 -0
  17. data/lib/navi/version.rb +1 -1
  18. data/navi.gemspec +6 -17
  19. data/spec/dummy/app/assets/javascripts/application.js +1 -1
  20. data/spec/dummy/app/controllers/categories_controller.rb +4 -4
  21. data/spec/dummy/app/controllers/menu_items_controller.rb +11 -4
  22. data/spec/dummy/app/controllers/pages_controller.rb +5 -4
  23. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  24. data/spec/dummy/config/application.rb +0 -1
  25. data/spec/dummy/config/navigation.rb +0 -0
  26. data/spec/dummy/db/seeds.rb +4 -6
  27. data/spec/dummy/vendor/assets/javascripts/nestedSortable.js +382 -0
  28. data/spec/navi/navi_spec.rb +3 -3
  29. data/spec/navi/navigable_spec.rb +2 -2
  30. data/spec/navi/navigator_spec.rb +7 -7
  31. data/spec/navi/renderers/simple_navigation/dynamic_item_spec.rb +49 -0
  32. data/spec/navi/renderers/simple_navigation/dynamic_items_spec.rb +30 -0
  33. data/spec/navi/renderers/simple_navigation/generates_uri_spec.rb +57 -0
  34. data/spec/navi/renderers/simple_navigation/renderer_spec.rb +41 -0
  35. metadata +229 -142
  36. data/.rvmrc +0 -1
  37. data/spec/navi/renderers/simple_navigation_spec.rb +0 -49
data/.gitignore CHANGED
@@ -48,3 +48,4 @@ rerun.txt
48
48
  spec/dummy/db/*.sql
49
49
  spec/dummy/db/*.sqlite3
50
50
  spec/dummy/log
51
+ spec/dummy/tmp
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p286
@@ -0,0 +1,3 @@
1
+ # 0.2.0
2
+
3
+ Add ability to pass namespace to generate all links under. `navi_render items, namespace: 'admin'`
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem 'haml'
6
+ gem 'apotomo', '~> 1.2.3'
7
+ gem 'simple-navigation'
8
+ gem 'pry'
@@ -1,62 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- navi (0.1.3)
4
+ navi (0.2.0)
5
5
  activerecord (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
+ easy_class_to_instance_method (= 0.0.1)
7
8
  ordered_tree (>= 0.1.6)
9
+ simple-navigation (~> 3.11.0)
8
10
 
9
11
  GEM
10
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
11
13
  specs:
12
- actionmailer (3.2.1)
13
- actionpack (= 3.2.1)
14
- mail (~> 2.4.0)
15
- actionpack (3.2.1)
16
- activemodel (= 3.2.1)
17
- activesupport (= 3.2.1)
14
+ actionmailer (3.2.13)
15
+ actionpack (= 3.2.13)
16
+ mail (~> 2.5.3)
17
+ actionpack (3.2.13)
18
+ activemodel (= 3.2.13)
19
+ activesupport (= 3.2.13)
18
20
  builder (~> 3.0.0)
19
21
  erubis (~> 2.7.0)
20
- journey (~> 1.0.1)
21
- rack (~> 1.4.0)
22
- rack-cache (~> 1.1)
22
+ journey (~> 1.0.4)
23
+ rack (~> 1.4.5)
24
+ rack-cache (~> 1.2)
23
25
  rack-test (~> 0.6.1)
24
- sprockets (~> 2.1.2)
25
- activemodel (3.2.1)
26
- activesupport (= 3.2.1)
26
+ sprockets (~> 2.2.1)
27
+ activemodel (3.2.13)
28
+ activesupport (= 3.2.13)
27
29
  builder (~> 3.0.0)
28
- activerecord (3.2.1)
29
- activemodel (= 3.2.1)
30
- activesupport (= 3.2.1)
31
- arel (~> 3.0.0)
30
+ activerecord (3.2.13)
31
+ activemodel (= 3.2.13)
32
+ activesupport (= 3.2.13)
33
+ arel (~> 3.0.2)
32
34
  tzinfo (~> 0.3.29)
33
- activeresource (3.2.1)
34
- activemodel (= 3.2.1)
35
- activesupport (= 3.2.1)
36
- activesupport (3.2.1)
37
- i18n (~> 0.6)
35
+ activeresource (3.2.13)
36
+ activemodel (= 3.2.13)
37
+ activesupport (= 3.2.13)
38
+ activesupport (3.2.13)
39
+ i18n (= 0.6.1)
38
40
  multi_json (~> 1.0)
39
- addressable (2.2.6)
40
- apotomo (1.2.2)
41
+ addressable (2.3.4)
42
+ apotomo (1.2.3)
41
43
  cells (>= 3.6.7)
42
44
  hooks (~> 0.2.0)
43
45
  onfire (~> 0.2.0)
44
- archive-tar-minitar (0.5.2)
45
- arel (3.0.0)
46
- builder (3.0.0)
47
- capybara (1.1.2)
46
+ arel (3.0.2)
47
+ builder (3.0.4)
48
+ capybara (2.1.0)
48
49
  mime-types (>= 1.16)
49
50
  nokogiri (>= 1.3.3)
50
51
  rack (>= 1.0.0)
51
52
  rack-test (>= 0.5.4)
52
- selenium-webdriver (~> 2.0)
53
- xpath (~> 0.1.4)
54
- cells (3.8.1)
55
- actionpack (~> 3.0)
56
- railties (~> 3.0)
57
- childprocess (0.3.1)
58
- ffi (~> 1.0.6)
59
- columnize (0.3.6)
53
+ xpath (~> 2.0)
54
+ cells (3.8.8)
55
+ actionpack (>= 3.0)
56
+ railties (>= 3.0)
57
+ childprocess (0.3.9)
58
+ ffi (~> 1.0, >= 1.0.11)
59
+ coderay (1.0.9)
60
60
  cucumber (0.10.7)
61
61
  builder (>= 2.1.2)
62
62
  diff-lcs (>= 1.1.2)
@@ -68,12 +68,14 @@ GEM
68
68
  cucumber (>= 0.10.5)
69
69
  nokogiri (>= 1.4.4)
70
70
  rack-test (>= 0.5.7)
71
- database_cleaner (0.7.1)
72
- diff-lcs (1.1.3)
71
+ database_cleaner (1.0.1)
72
+ diff-lcs (1.2.4)
73
+ easy_class_to_instance_method (0.0.1)
74
+ activesupport (>= 3.0.0)
73
75
  erubis (2.7.0)
74
- factory_girl (2.5.1)
75
- activesupport
76
- ffi (1.0.11)
76
+ factory_girl (4.2.0)
77
+ activesupport (>= 3.0.0)
78
+ ffi (1.8.1)
77
79
  gherkin (2.4.21)
78
80
  json (>= 1.4.6)
79
81
  guard (0.3.4)
@@ -81,136 +83,117 @@ GEM
81
83
  guard-cucumber (0.3.4)
82
84
  cucumber (~> 0.10.0)
83
85
  guard (~> 0.3.0)
84
- guard-rspec (0.3.1)
85
- guard (>= 0.2.2)
86
- haml (3.1.4)
87
- has_scope (0.5.1)
88
- hike (1.2.1)
89
- hooks (0.2.0)
90
- i18n (0.6.0)
91
- inherited_resources (1.3.0)
92
- has_scope (~> 0.5.0)
93
- responders (~> 0.6.0)
94
- journey (1.0.1)
95
- jquery-rails (2.0.0)
96
- railties (>= 3.2.0.beta, < 5.0)
97
- thor (~> 0.14)
98
- json (1.6.5)
99
- launchy (2.0.5)
100
- addressable (~> 2.2.6)
101
- libnotify (0.7.2)
102
- linecache19 (0.5.12)
103
- ruby_core_source (>= 0.1.4)
104
- mail (2.4.1)
105
- i18n (>= 0.4.0)
86
+ haml (4.0.3)
87
+ tilt
88
+ hike (1.2.3)
89
+ hooks (0.2.2)
90
+ i18n (0.6.1)
91
+ journey (1.0.4)
92
+ jquery-rails (2.2.2)
93
+ railties (>= 3.0, < 5.0)
94
+ thor (>= 0.14, < 2.0)
95
+ json (1.8.0)
96
+ launchy (2.3.0)
97
+ addressable (~> 2.3)
98
+ mail (2.5.4)
106
99
  mime-types (~> 1.16)
107
100
  treetop (~> 1.4.8)
108
- mime-types (1.17.2)
109
- multi_json (1.0.4)
101
+ method_source (0.8.1)
102
+ mime-types (1.23)
103
+ multi_json (1.7.6)
110
104
  nifty-generators (0.4.6)
111
- nokogiri (1.5.0)
105
+ nokogiri (1.5.9)
112
106
  onfire (0.2.0)
113
107
  ordered_tree (0.2.1)
114
108
  activerecord (>= 3.1.1)
115
109
  polyglot (0.3.3)
116
- rack (1.4.1)
117
- rack-cache (1.1)
110
+ pry (0.9.12.2)
111
+ coderay (~> 1.0.5)
112
+ method_source (~> 0.8)
113
+ slop (~> 3.4)
114
+ rack (1.4.5)
115
+ rack-cache (1.2)
118
116
  rack (>= 0.4)
119
- rack-ssl (1.3.2)
117
+ rack-ssl (1.3.3)
120
118
  rack
121
- rack-test (0.6.1)
119
+ rack-test (0.6.2)
122
120
  rack (>= 1.0)
123
- rails (3.2.1)
124
- actionmailer (= 3.2.1)
125
- actionpack (= 3.2.1)
126
- activerecord (= 3.2.1)
127
- activeresource (= 3.2.1)
128
- activesupport (= 3.2.1)
121
+ rails (3.2.13)
122
+ actionmailer (= 3.2.13)
123
+ actionpack (= 3.2.13)
124
+ activerecord (= 3.2.13)
125
+ activeresource (= 3.2.13)
126
+ activesupport (= 3.2.13)
129
127
  bundler (~> 1.0)
130
- railties (= 3.2.1)
131
- railties (3.2.1)
132
- actionpack (= 3.2.1)
133
- activesupport (= 3.2.1)
128
+ railties (= 3.2.13)
129
+ railties (3.2.13)
130
+ actionpack (= 3.2.13)
131
+ activesupport (= 3.2.13)
134
132
  rack-ssl (~> 1.3.2)
135
133
  rake (>= 0.8.7)
136
134
  rdoc (~> 3.4)
137
- thor (~> 0.14.6)
138
- rake (0.9.2.2)
139
- rb-inotify (0.8.8)
140
- ffi (>= 0.5.0)
141
- rdoc (3.12)
135
+ thor (>= 0.14.6, < 2.0)
136
+ rake (10.0.4)
137
+ rdoc (3.12.2)
142
138
  json (~> 1.4)
143
- responders (0.6.5)
144
- rspec (2.6.0)
145
- rspec-core (~> 2.6.0)
146
- rspec-expectations (~> 2.6.0)
147
- rspec-mocks (~> 2.6.0)
148
- rspec-core (2.6.4)
149
- rspec-expectations (2.6.0)
150
- diff-lcs (~> 1.1.2)
151
- rspec-mocks (2.6.0)
152
- rspec-rails (2.6.1)
153
- actionpack (~> 3.0)
154
- activesupport (~> 3.0)
155
- railties (~> 3.0)
156
- rspec (~> 2.6.0)
157
- ruby-debug-base19 (0.11.25)
158
- columnize (>= 0.3.1)
159
- linecache19 (>= 0.5.11)
160
- ruby_core_source (>= 0.1.4)
161
- ruby-debug19 (0.11.6)
162
- columnize (>= 0.3.1)
163
- linecache19 (>= 0.5.11)
164
- ruby-debug-base19 (>= 0.11.19)
165
- ruby_core_source (0.1.5)
166
- archive-tar-minitar (>= 0.5.2)
167
- rubyzip (0.9.5)
168
- selenium-webdriver (2.18.0)
139
+ rspec-core (2.13.1)
140
+ rspec-expectations (2.13.0)
141
+ diff-lcs (>= 1.1.3, < 2.0)
142
+ rspec-mocks (2.13.1)
143
+ rspec-rails (2.13.2)
144
+ actionpack (>= 3.0)
145
+ activesupport (>= 3.0)
146
+ railties (>= 3.0)
147
+ rspec-core (~> 2.13.0)
148
+ rspec-expectations (~> 2.13.0)
149
+ rspec-mocks (~> 2.13.0)
150
+ rubyzip (0.9.9)
151
+ selenium-webdriver (2.32.1)
169
152
  childprocess (>= 0.2.5)
170
- ffi (~> 1.0.9)
171
- multi_json (~> 1.0.4)
153
+ multi_json (~> 1.0)
172
154
  rubyzip
173
- simple-navigation (3.2.0)
155
+ websocket (~> 1.0.4)
156
+ simple-navigation (3.11.0)
174
157
  activesupport (>= 2.3.2)
175
- sprockets (2.1.2)
158
+ slop (3.4.4)
159
+ sprockets (2.2.2)
176
160
  hike (~> 1.2)
161
+ multi_json (~> 1.0)
177
162
  rack (~> 1.0)
178
163
  tilt (~> 1.1, != 1.3.0)
179
- sqlite3 (1.3.5)
180
- term-ansicolor (1.0.7)
164
+ sqlite3 (1.3.7)
165
+ term-ansicolor (1.2.2)
166
+ tins (~> 0.8)
181
167
  thor (0.14.6)
182
- tilt (1.3.3)
183
- treetop (1.4.10)
168
+ tilt (1.4.1)
169
+ tins (0.8.0)
170
+ treetop (1.4.14)
184
171
  polyglot
185
172
  polyglot (>= 0.3.1)
186
- tzinfo (0.3.31)
187
- xpath (0.1.4)
173
+ tzinfo (0.3.37)
174
+ websocket (1.0.7)
175
+ xpath (2.0.0)
188
176
  nokogiri (~> 1.3)
189
177
 
190
178
  PLATFORMS
191
179
  ruby
192
180
 
193
181
  DEPENDENCIES
194
- apotomo (~> 1.2.2)
195
- bundler (~> 1.0.0)
182
+ apotomo (~> 1.2.3)
196
183
  capybara (>= 1.0.0.rc1)
197
184
  cucumber
198
185
  cucumber-rails (= 0.5.2)
199
186
  database_cleaner
200
- factory_girl (~> 2.5.1)
187
+ factory_girl (~> 4.2.0)
201
188
  guard-cucumber (= 0.3.4)
202
- guard-rspec
203
189
  haml
204
- inherited_resources (~> 1.3.0)
205
- jquery-rails (~> 2.0.0)
190
+ jquery-rails (~> 2.2.1)
206
191
  launchy
207
- libnotify
208
192
  navi!
209
193
  nifty-generators
194
+ pry
210
195
  rails (~> 3.2.0)
211
- rb-inotify
212
- rspec (~> 2.6.0)
213
- rspec-rails (~> 2.6.1)
214
- ruby-debug19
215
- simple-navigation (= 3.2.0)
196
+ rspec-rails (~> 2.13.2)
197
+ selenium-webdriver
198
+ simple-navigation
216
199
  sqlite3
data/README.md CHANGED
@@ -58,6 +58,14 @@ You must supply an array of top-most items to render. What do I mean? "top-most"
58
58
 
59
59
  You can create your own renderer too. For this, see the wiki. I could add these into the gem. Send me a pull request.
60
60
 
61
+ ## Namespace
62
+
63
+ You can render all your links in a namespace:
64
+
65
+ <%= navi_render NavItem.roots, namespace: 'preview' %>
66
+
67
+ This is useful if you want to generate the same links but have them all point to a different route. For example, you have a CMS and there's a preview section where you want the links that are generated to be the same, yet point to all other preview pages in the CMS.
68
+
61
69
  # Contributing to navigable
62
70
 
63
71
  _To develop and run tests, see the Gemfile and read the comments right above the :development, :test, :cucumber group._
@@ -1,3 +1,3 @@
1
1
  Given /^a category "([^"]*)" exists$/ do |name|
2
- Factory :category, :name => name
2
+ FactoryGirl.create :category, name: name
3
3
  end
@@ -1,3 +1,3 @@
1
1
  Given /^a page "([^"]*)" exists$/ do |name|
2
- Factory :page, :name => name
2
+ FactoryGirl.create :page, :name => name
3
3
  end
@@ -1,6 +1,10 @@
1
1
  ENV["RAILS_ENV"] ||= "test"
2
- require File.expand_path("../../../spec/dummy/config/environment.rb", __FILE__)
3
- require File.expand_path("../../../spec/blueprints.rb", __FILE__)
2
+ SPEC_DIR = File.join(File.dirname(__FILE__), '..', '..', 'spec')
3
+ require File.join(SPEC_DIR, 'dummy', 'config', 'environment')
4
+
5
+ require 'factory_girl'
6
+ require File.join(SPEC_DIR, 'factories')
7
+ Dir.glob(File.join(SPEC_DIR, 'factories', '**', '*.rb')).each {|f| require f}
4
8
 
5
9
  require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
6
10
  require 'cucumber/rails/rspec'
@@ -56,6 +60,7 @@ if defined?(ActiveRecord::Base)
56
60
  begin
57
61
  require 'database_cleaner'
58
62
  DatabaseCleaner.strategy = :truncation
63
+ DatabaseCleaner.clean
59
64
  rescue LoadError => ignore_if_database_cleaner_not_present
60
65
  end
61
66
  end
@@ -1,3 +1,4 @@
1
+ require 'easy_class_to_instance_method'
1
2
  require 'active_support'
2
3
  require "active_support/core_ext/module" # so we can use mattr_accessor
3
4
  require 'active_record'
@@ -18,5 +19,5 @@ module Navi
18
19
  @@navigator ||= :nav_item
19
20
 
20
21
  mattr_accessor :renderer
21
- @@renderer ||= Navi::Renderers::SimpleNavigation
22
+ @@renderer ||= Navi::Renderers::SimpleNavigation::Renderer
22
23
  end
@@ -5,8 +5,6 @@ module Navi
5
5
 
6
6
  def initialize(context)
7
7
  @context = context
8
- @controller = controller_from @context
9
- @template = template_from @controller
10
8
  end
11
9
 
12
10
  def render(collection)
@@ -15,16 +13,20 @@ module Navi
15
13
 
16
14
  private
17
15
 
18
- # Pretty much lifted from
19
- # https://github.com/andi/simple-navigation/blob/master/lib/simple_navigation/adapters/rails.rb
20
- def controller_from(context)
21
- context.respond_to?(:controller) ? context.controller : context
16
+ def controller
17
+ @controller ||= if @context.respond_to?(:controller)
18
+ @context.controller
19
+ else
20
+ @context
21
+ end
22
22
  end
23
23
 
24
- # Pretty much lifted from
25
- # https://github.com/andi/simple-navigation/blob/master/lib/simple_navigation/adapters/rails.rb
26
- def template_from(controller)
27
- controller.respond_to?(:view_context) ? controller.view_context : controller.instance_variable_get(:@template)
24
+ def template
25
+ @template ||= if controller.respond_to?(:view_context)
26
+ controller.view_context
27
+ else
28
+ controller.instance_variable_get(:@template)
29
+ end
28
30
  end
29
31
  end
30
32
  end