navi 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,10 +5,17 @@ gem "activesupport", ">= 3.0.0"
5
5
  gem "activerecord", ">= 3.0.0"
6
6
  gem "ordered_tree", "0.1.2"
7
7
 
8
- # Comment out group block first because cucumber features were complaining that
9
- # These gems didn't exist, even if the group included the cucumber/test
10
- # group! `bundle exec guard` doesn't work!
11
- #group :development, :test, :cucumber do
8
+ # If you're going to do any development and run any tests, comment out the start
9
+ # and end of the group block
10
+ # * group :development, :test, :cucumber do
11
+ # * end
12
+ #
13
+ # If you don't, cucumber features will complaining that
14
+ # these gems didn't exist, even if the group below includes
15
+ # :test and :cucumber environments!
16
+ #
17
+ # Just remember to uncomment them when you publish (or make a pull request).
18
+ group :development, :test, :cucumber do
12
19
  gem "rspec", "~> 2.6.0"
13
20
  gem "bundler", "~> 1.0.0"
14
21
  gem "jeweler", "~> 1.5.2"
@@ -38,4 +45,4 @@ gem "ordered_tree", "0.1.2"
38
45
  gem 'libnotify'
39
46
  gem 'rb-inotify'
40
47
  gem 'nifty-generators'
41
- #end
48
+ end
data/README.textile CHANGED
@@ -1,21 +1,69 @@
1
1
  h1. navigable
2
2
 
3
- *navigable* puts the navigation (aka menu) in the database. That means you and/or your users can edit and control it. It was made with "WordPress' menu editor":http://dl.dropbox.com/u/16150176/until%20dec%202013/wp-menu.png in mind.
3
+ *navi* puts the navigation (aka menu) in the database. That means you and/or your users can edit and control it. It was made with "WordPress' menu editor":http://dl.dropbox.com/u/16150176/until%20dec%202013/wp-menu.png in mind.
4
+
5
+ Here are a few things to keep in mind:
6
+
7
+ * navigable - this is the thing in the database, like a Page or a Category, that you've allowed to be added to the navigation (aka menu).
8
+ * navigator - this is the record that may or may not point to the navigable item. This is a database record that represents the navigation item (menu item).
9
+ * renderer - with all the navigables and navigators, the renderer puts it all together and creates the HTML to form the navigation.
4
10
 
5
11
  h2. Installation
6
12
 
7
- In your Gemfile: @gem 'navigable'@
13
+ This has only been tested with Rails 3.0.x.
14
+
15
+ In your Gemfile: @gem 'navi'@
8
16
 
9
17
  h2. Usage
10
18
 
11
- h2. More on renderers
19
+ All navigation items (aka menu items) are database entries. Thus, you should create your own model for this. By default, the model name @navi@ looks for is @nav_item@, so go ahead and make it.
20
+
21
+ pre. class NavItem < Navi::Navigator::Base
22
+ # Yup, you don't need to put anything here since most of what you want comes from Navi::Navigator::Base
23
+ # I'll eventually explain what you can override in the wiki.
24
+ end
25
+
26
+ Then, whatever you want to be able to become a navigation item in your navigation (menu), add @navigable@ to the class, like we do to @Page@:
27
+
28
+ pre. class Page < ActiveRecord::Base
29
+ navigable
30
+ end
31
+
32
+ With this, Page will get the following instance methods:
33
+
34
+ pre. @page.to_navigator # initialized a new NavItem instance that can be saved into the database with a .save call on it.
35
+ @page.to_navigator! # initializes and saves the new NavItem, all in one call.
36
+
37
+ You can pass any of the following arguments, in a form of a hash, into @to_navigator@:
38
+
39
+ * :label
40
+ * :title
41
+ * :link
42
+ * :highlights_on
43
+ * :parent_id
44
+ * :position
45
+ * any other argument you want saved into the table of @nav_items@ table
46
+
47
+ _For more information about each item, see the wiki._
48
+
49
+ h2. Rendering it onto a page
50
+
51
+ You've got your nav_items all set and you want to render it to the menu. I've created a Renderer - the SimpleNavigation renderer that fetches all the nav_items in the database and renders it on the page using "andi's simple-navigation gem":https://github.com/andi/simple-navigation. This is the default choice. To render stuff into the page, you get the @navi_render@ helper:
52
+
53
+ pre. <%= navi_render NavItem.roots %>
54
+
55
+ You must supply an array of top-most items to render. What do I mean? "top-most" means all the root items, for example, or a generation of items. This will render that generation and all their children in a nested @ul@. See @lib/navi/renderers/simple_navigation.rb@ for more info.
56
+
57
+ You can create your own renderer too. For this, see the wiki. I could add these into the gem. Send me a pull request.
12
58
 
13
59
  h2. Contributing to navigable
60
+
61
+ _To develop and run tests, see the Gemfile and read the comments right above the :development, :test, :cucumber group._
14
62
 
15
63
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
64
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
65
  * Fork the project
18
- * Start a feature/bugfix branch
66
+ * Start a feature/hotfix branch
19
67
  * Commit and push until you are happy with your contribution
20
68
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
69
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.6
@@ -7,6 +7,7 @@ Feature: So that I can create a menu for my viewers to navigate my site
7
7
  Given a page "Home" exists
8
8
  And a category "Misc" exists
9
9
  And I am on the menu items page
10
+ And show me the page
10
11
  When I create the page "Home" menu item
11
12
  Then I should see "Home" in the list of menu items
12
13
  When I create the category "Misc" menu item
@@ -15,13 +15,20 @@ module Navi
15
15
  def create_dynamic_items(collection)
16
16
  nav = []
17
17
  collection.each do |nav_item|
18
- nav << {
19
- :key => @template.dom_id(nav_item).to_sym,
20
- :name => nav_item.label,
21
- :url => @template.polymorphic_path(nav_item.link),
22
- :options => {:title => nav_item.title, :class => nav_item.class.name.underscore},
23
- :items => create_dynamic_items(nav_item.children)
24
- }
18
+ item = {}
19
+ item[:key] = @template.dom_id(nav_item).to_sym
20
+ item[:name] = nav_item.label
21
+ if nav_item.link.is_a?(String)
22
+ item[:url] = nav_item.link
23
+ else # it's a database record then!
24
+ puts "This is the link: #{nav_item.link.inspect}"
25
+ item[:url] = @template.polymorphic_path(nav_item.link)
26
+ #item[:url] = "/"
27
+ end
28
+ item[:options] = {:title => nav_item.title, :class => nav_item.class.name.underscore}
29
+ item[:items] = create_dynamic_items(nav_item.children)
30
+
31
+ nav << item
25
32
  end
26
33
  nav
27
34
  end
data/navi.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{navi}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ramon Tayag"]
@@ -183,34 +183,34 @@ Gem::Specification.new do |s|
183
183
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
184
184
  s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
185
185
  s.add_runtime_dependency(%q<ordered_tree>, ["= 0.1.2"])
186
- s.add_runtime_dependency(%q<rspec>, ["~> 2.6.0"])
187
- s.add_runtime_dependency(%q<bundler>, ["~> 1.0.0"])
188
- s.add_runtime_dependency(%q<jeweler>, ["~> 1.5.2"])
189
- s.add_runtime_dependency(%q<rcov>, [">= 0"])
190
- s.add_runtime_dependency(%q<simple-navigation>, ["= 3.2.0"])
191
- s.add_runtime_dependency(%q<inherited_resources>, [">= 0"])
192
- s.add_runtime_dependency(%q<guard-rspec>, [">= 0"])
193
- s.add_runtime_dependency(%q<libnotify>, [">= 0"])
194
- s.add_runtime_dependency(%q<rb-inotify>, [">= 0"])
195
- s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
196
- s.add_runtime_dependency(%q<rake>, ["= 0.8.7"])
197
- s.add_runtime_dependency(%q<apotomo>, ["= 1.1.1"])
198
- s.add_runtime_dependency(%q<rails>, ["= 3.0.7"])
199
- s.add_runtime_dependency(%q<haml>, [">= 0"])
200
- s.add_runtime_dependency(%q<simple-navigation>, ["= 3.2.0"])
201
- s.add_runtime_dependency(%q<jquery-rails>, [">= 1.0.3"])
202
- s.add_runtime_dependency(%q<rspec-rails>, ["= 2.6.1"])
203
- s.add_runtime_dependency(%q<cucumber-rails>, ["= 0.5.2"])
204
- s.add_runtime_dependency(%q<cucumber>, [">= 0"])
205
- s.add_runtime_dependency(%q<capybara>, [">= 1.0.0.rc1"])
206
- s.add_runtime_dependency(%q<database_cleaner>, [">= 0"])
207
- s.add_runtime_dependency(%q<launchy>, [">= 0"])
208
- s.add_runtime_dependency(%q<machinist>, [">= 0"])
209
- s.add_runtime_dependency(%q<faker>, [">= 0"])
210
- s.add_runtime_dependency(%q<guard-cucumber>, ["= 0.3.4"])
211
- s.add_runtime_dependency(%q<libnotify>, [">= 0"])
212
- s.add_runtime_dependency(%q<rb-inotify>, [">= 0"])
213
- s.add_runtime_dependency(%q<nifty-generators>, [">= 0"])
186
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
187
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
188
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
189
+ s.add_development_dependency(%q<rcov>, [">= 0"])
190
+ s.add_development_dependency(%q<simple-navigation>, ["= 3.2.0"])
191
+ s.add_development_dependency(%q<inherited_resources>, [">= 0"])
192
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
193
+ s.add_development_dependency(%q<libnotify>, [">= 0"])
194
+ s.add_development_dependency(%q<rb-inotify>, [">= 0"])
195
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
196
+ s.add_development_dependency(%q<rake>, ["= 0.8.7"])
197
+ s.add_development_dependency(%q<apotomo>, ["= 1.1.1"])
198
+ s.add_development_dependency(%q<rails>, ["= 3.0.7"])
199
+ s.add_development_dependency(%q<haml>, [">= 0"])
200
+ s.add_development_dependency(%q<simple-navigation>, ["= 3.2.0"])
201
+ s.add_development_dependency(%q<jquery-rails>, [">= 1.0.3"])
202
+ s.add_development_dependency(%q<rspec-rails>, ["= 2.6.1"])
203
+ s.add_development_dependency(%q<cucumber-rails>, ["= 0.5.2"])
204
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
205
+ s.add_development_dependency(%q<capybara>, [">= 1.0.0.rc1"])
206
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
207
+ s.add_development_dependency(%q<launchy>, [">= 0"])
208
+ s.add_development_dependency(%q<machinist>, [">= 0"])
209
+ s.add_development_dependency(%q<faker>, [">= 0"])
210
+ s.add_development_dependency(%q<guard-cucumber>, ["= 0.3.4"])
211
+ s.add_development_dependency(%q<libnotify>, [">= 0"])
212
+ s.add_development_dependency(%q<rb-inotify>, [">= 0"])
213
+ s.add_development_dependency(%q<nifty-generators>, [">= 0"])
214
214
  else
215
215
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
216
216
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
@@ -3,10 +3,6 @@ class MenuItemsController < InheritedResources::Base
3
3
  root << widget(:menu_editor)
4
4
  end
5
5
 
6
- def index
7
- @simple_navigation = []
8
- end
9
-
10
6
  def update
11
7
  update! do |success, failure|
12
8
  success.html {redirect_to menu_items_path}
@@ -141,8 +141,14 @@ describe MenuItem do
141
141
 
142
142
  describe "#highlights_on," do
143
143
  describe "when the link field is not nil" do
144
- it "should return the value converted to regex" do
145
- MenuItem.new(:highlights_on => "holy").highlights_on.should == /holy/
144
+ it "should return the string value converted to regex" do
145
+ item = MenuItem.create(:highlights_on => "holy")
146
+ item.highlights_on.should == /holy/
147
+ end
148
+
149
+ it "should return the regexp value if set to regexp" do
150
+ item = MenuItem.create(:highlights_on => /holy/)
151
+ item.highlights_on.should == /holy/
146
152
  end
147
153
  end
148
154
 
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,7 @@ Capybara.default_selector = :css
19
19
 
20
20
  # Run down then up any available migration in the dummy app
21
21
  def migrate(direction)
22
+ puts "Will migrate #{direction}"
22
23
  migration_directory = File.expand_path "../dummy/db/migrate", __FILE__
23
24
  migration_files = Dir["#{migration_directory}/[0-9]*_*.rb"]
24
25
  migration_files.each {|migration_file| require migration_file} # require them so we can execute them
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag
@@ -67,7 +67,7 @@ dependencies:
67
67
  version_requirements: *id003
68
68
  prerelease: false
69
69
  - !ruby/object:Gem::Dependency
70
- type: :runtime
70
+ type: :development
71
71
  requirement: &id004 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
@@ -83,7 +83,7 @@ dependencies:
83
83
  version_requirements: *id004
84
84
  prerelease: false
85
85
  - !ruby/object:Gem::Dependency
86
- type: :runtime
86
+ type: :development
87
87
  requirement: &id005 !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
@@ -99,7 +99,7 @@ dependencies:
99
99
  version_requirements: *id005
100
100
  prerelease: false
101
101
  - !ruby/object:Gem::Dependency
102
- type: :runtime
102
+ type: :development
103
103
  requirement: &id006 !ruby/object:Gem::Requirement
104
104
  none: false
105
105
  requirements:
@@ -115,7 +115,7 @@ dependencies:
115
115
  version_requirements: *id006
116
116
  prerelease: false
117
117
  - !ruby/object:Gem::Dependency
118
- type: :runtime
118
+ type: :development
119
119
  requirement: &id007 !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements:
@@ -129,7 +129,7 @@ dependencies:
129
129
  version_requirements: *id007
130
130
  prerelease: false
131
131
  - !ruby/object:Gem::Dependency
132
- type: :runtime
132
+ type: :development
133
133
  requirement: &id008 !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
@@ -145,7 +145,7 @@ dependencies:
145
145
  version_requirements: *id008
146
146
  prerelease: false
147
147
  - !ruby/object:Gem::Dependency
148
- type: :runtime
148
+ type: :development
149
149
  requirement: &id009 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
@@ -159,7 +159,7 @@ dependencies:
159
159
  version_requirements: *id009
160
160
  prerelease: false
161
161
  - !ruby/object:Gem::Dependency
162
- type: :runtime
162
+ type: :development
163
163
  requirement: &id010 !ruby/object:Gem::Requirement
164
164
  none: false
165
165
  requirements:
@@ -173,7 +173,7 @@ dependencies:
173
173
  version_requirements: *id010
174
174
  prerelease: false
175
175
  - !ruby/object:Gem::Dependency
176
- type: :runtime
176
+ type: :development
177
177
  requirement: &id011 !ruby/object:Gem::Requirement
178
178
  none: false
179
179
  requirements:
@@ -187,7 +187,7 @@ dependencies:
187
187
  version_requirements: *id011
188
188
  prerelease: false
189
189
  - !ruby/object:Gem::Dependency
190
- type: :runtime
190
+ type: :development
191
191
  requirement: &id012 !ruby/object:Gem::Requirement
192
192
  none: false
193
193
  requirements:
@@ -201,7 +201,7 @@ dependencies:
201
201
  version_requirements: *id012
202
202
  prerelease: false
203
203
  - !ruby/object:Gem::Dependency
204
- type: :runtime
204
+ type: :development
205
205
  requirement: &id013 !ruby/object:Gem::Requirement
206
206
  none: false
207
207
  requirements:
@@ -215,7 +215,7 @@ dependencies:
215
215
  version_requirements: *id013
216
216
  prerelease: false
217
217
  - !ruby/object:Gem::Dependency
218
- type: :runtime
218
+ type: :development
219
219
  requirement: &id014 !ruby/object:Gem::Requirement
220
220
  none: false
221
221
  requirements:
@@ -231,7 +231,7 @@ dependencies:
231
231
  version_requirements: *id014
232
232
  prerelease: false
233
233
  - !ruby/object:Gem::Dependency
234
- type: :runtime
234
+ type: :development
235
235
  requirement: &id015 !ruby/object:Gem::Requirement
236
236
  none: false
237
237
  requirements:
@@ -247,7 +247,7 @@ dependencies:
247
247
  version_requirements: *id015
248
248
  prerelease: false
249
249
  - !ruby/object:Gem::Dependency
250
- type: :runtime
250
+ type: :development
251
251
  requirement: &id016 !ruby/object:Gem::Requirement
252
252
  none: false
253
253
  requirements:
@@ -263,7 +263,7 @@ dependencies:
263
263
  version_requirements: *id016
264
264
  prerelease: false
265
265
  - !ruby/object:Gem::Dependency
266
- type: :runtime
266
+ type: :development
267
267
  requirement: &id017 !ruby/object:Gem::Requirement
268
268
  none: false
269
269
  requirements:
@@ -277,7 +277,7 @@ dependencies:
277
277
  version_requirements: *id017
278
278
  prerelease: false
279
279
  - !ruby/object:Gem::Dependency
280
- type: :runtime
280
+ type: :development
281
281
  requirement: &id018 !ruby/object:Gem::Requirement
282
282
  none: false
283
283
  requirements:
@@ -293,7 +293,7 @@ dependencies:
293
293
  version_requirements: *id018
294
294
  prerelease: false
295
295
  - !ruby/object:Gem::Dependency
296
- type: :runtime
296
+ type: :development
297
297
  requirement: &id019 !ruby/object:Gem::Requirement
298
298
  none: false
299
299
  requirements:
@@ -309,7 +309,7 @@ dependencies:
309
309
  version_requirements: *id019
310
310
  prerelease: false
311
311
  - !ruby/object:Gem::Dependency
312
- type: :runtime
312
+ type: :development
313
313
  requirement: &id020 !ruby/object:Gem::Requirement
314
314
  none: false
315
315
  requirements:
@@ -325,7 +325,7 @@ dependencies:
325
325
  version_requirements: *id020
326
326
  prerelease: false
327
327
  - !ruby/object:Gem::Dependency
328
- type: :runtime
328
+ type: :development
329
329
  requirement: &id021 !ruby/object:Gem::Requirement
330
330
  none: false
331
331
  requirements:
@@ -341,7 +341,7 @@ dependencies:
341
341
  version_requirements: *id021
342
342
  prerelease: false
343
343
  - !ruby/object:Gem::Dependency
344
- type: :runtime
344
+ type: :development
345
345
  requirement: &id022 !ruby/object:Gem::Requirement
346
346
  none: false
347
347
  requirements:
@@ -355,7 +355,7 @@ dependencies:
355
355
  version_requirements: *id022
356
356
  prerelease: false
357
357
  - !ruby/object:Gem::Dependency
358
- type: :runtime
358
+ type: :development
359
359
  requirement: &id023 !ruby/object:Gem::Requirement
360
360
  none: false
361
361
  requirements:
@@ -373,7 +373,7 @@ dependencies:
373
373
  version_requirements: *id023
374
374
  prerelease: false
375
375
  - !ruby/object:Gem::Dependency
376
- type: :runtime
376
+ type: :development
377
377
  requirement: &id024 !ruby/object:Gem::Requirement
378
378
  none: false
379
379
  requirements:
@@ -387,7 +387,7 @@ dependencies:
387
387
  version_requirements: *id024
388
388
  prerelease: false
389
389
  - !ruby/object:Gem::Dependency
390
- type: :runtime
390
+ type: :development
391
391
  requirement: &id025 !ruby/object:Gem::Requirement
392
392
  none: false
393
393
  requirements:
@@ -401,7 +401,7 @@ dependencies:
401
401
  version_requirements: *id025
402
402
  prerelease: false
403
403
  - !ruby/object:Gem::Dependency
404
- type: :runtime
404
+ type: :development
405
405
  requirement: &id026 !ruby/object:Gem::Requirement
406
406
  none: false
407
407
  requirements:
@@ -415,7 +415,7 @@ dependencies:
415
415
  version_requirements: *id026
416
416
  prerelease: false
417
417
  - !ruby/object:Gem::Dependency
418
- type: :runtime
418
+ type: :development
419
419
  requirement: &id027 !ruby/object:Gem::Requirement
420
420
  none: false
421
421
  requirements:
@@ -429,7 +429,7 @@ dependencies:
429
429
  version_requirements: *id027
430
430
  prerelease: false
431
431
  - !ruby/object:Gem::Dependency
432
- type: :runtime
432
+ type: :development
433
433
  requirement: &id028 !ruby/object:Gem::Requirement
434
434
  none: false
435
435
  requirements:
@@ -445,7 +445,7 @@ dependencies:
445
445
  version_requirements: *id028
446
446
  prerelease: false
447
447
  - !ruby/object:Gem::Dependency
448
- type: :runtime
448
+ type: :development
449
449
  requirement: &id029 !ruby/object:Gem::Requirement
450
450
  none: false
451
451
  requirements:
@@ -459,7 +459,7 @@ dependencies:
459
459
  version_requirements: *id029
460
460
  prerelease: false
461
461
  - !ruby/object:Gem::Dependency
462
- type: :runtime
462
+ type: :development
463
463
  requirement: &id030 !ruby/object:Gem::Requirement
464
464
  none: false
465
465
  requirements:
@@ -473,7 +473,7 @@ dependencies:
473
473
  version_requirements: *id030
474
474
  prerelease: false
475
475
  - !ruby/object:Gem::Dependency
476
- type: :runtime
476
+ type: :development
477
477
  requirement: &id031 !ruby/object:Gem::Requirement
478
478
  none: false
479
479
  requirements: