simple-navigation 2.7.3 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
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,7 +1,6 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
2
  require 'rubygems'
3
3
  require 'spec'
4
- require 'active_support'
5
4
  require 'action_controller'
6
5
 
7
6
  module Rails
@@ -15,11 +14,14 @@ $:.unshift File.join(File.dirname(__FILE__), '../lib')
15
14
 
16
15
  require 'simple_navigation'
17
16
 
18
- SimpleNavigation.rails_root = './'
17
+ # SimpleNavigation.root = './'
18
+ RAILS_ROOT = './' unless defined?(RAILS_ROOT)
19
+ RAILS_ENV = 'test' unless defined?(RAILS_ENV)
20
+
19
21
 
20
22
  # Spec::Runner.configure do |config|
21
23
  # no special config
22
- # endx
24
+ # end
23
25
 
24
26
  # spec helper methods
25
27
  def sub_items
@@ -53,12 +55,12 @@ def primary_item(key)
53
55
  end
54
56
 
55
57
  def select_item(key)
56
- if(key == :subnav1)
58
+ if(key == :subnav1)
57
59
  select_item(:invoices)
58
60
  primary_item(:invoices) do |item|
59
61
  item.instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}.stub!(:selected? => true)
60
62
  end
61
-
63
+
62
64
  end
63
65
  primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
64
66
  end
@@ -70,3 +72,12 @@ def subnav_container
70
72
  container.instance_variable_set(:@items, items)
71
73
  container
72
74
  end
75
+
76
+ def setup_renderer_for(renderer_class, framework, options)
77
+ adapter = case framework
78
+ when :rails
79
+ SimpleNavigation::Adapters::Rails.new(stub(:context, :view_context => ActionView::Base.new))
80
+ end
81
+ SimpleNavigation.stub!(:adapter => adapter)
82
+ @renderer = renderer_class.new(options)
83
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ prerelease: true
6
5
  segments:
7
- - 2
8
- - 7
9
6
  - 3
10
- version: 2.7.3
7
+ - 0
8
+ - 0
9
+ - beta1
10
+ version: 3.0.0.beta1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andi Schacke
@@ -15,18 +15,16 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-26 00:00:00 +02:00
18
+ date: 2010-09-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 15
30
28
  segments:
31
29
  - 1
32
30
  - 2
@@ -34,6 +32,20 @@ dependencies:
34
32
  version: 1.2.8
35
33
  type: :development
36
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 3
45
+ - 2
46
+ version: 2.3.2
47
+ type: :runtime
48
+ version_requirements: *id002
37
49
  description: With the simple-navigation gem installed you can easily create multilevel navigations for your Ruby on Rails applications. The navigation is defined in a single configuration file. It supports automatic as well as explicit highlighting of the currently active navigation.
38
50
  email: andreas.schacke@gmail.com
39
51
  executables: []
@@ -53,31 +65,39 @@ files:
53
65
  - lib/generators/navigation_config/navigation_config_generator.rb
54
66
  - lib/simple-navigation.rb
55
67
  - lib/simple_navigation.rb
56
- - lib/simple_navigation/configuration.rb
57
- - lib/simple_navigation/controller_methods.rb
58
- - lib/simple_navigation/helpers.rb
59
- - lib/simple_navigation/initializer.rb
60
- - lib/simple_navigation/item.rb
61
- - lib/simple_navigation/item_adapter.rb
62
- - lib/simple_navigation/item_container.rb
63
- - lib/simple_navigation/items_provider.rb
64
- - lib/simple_navigation/railtie.rb
65
- - lib/simple_navigation/renderer/base.rb
66
- - lib/simple_navigation/renderer/breadcrumbs.rb
67
- - lib/simple_navigation/renderer/links.rb
68
- - lib/simple_navigation/renderer/list.rb
68
+ - lib/simple_navigation/adapters.rb
69
+ - lib/simple_navigation/adapters/base.rb
70
+ - lib/simple_navigation/adapters/padrino.rb
71
+ - lib/simple_navigation/adapters/rails.rb
72
+ - lib/simple_navigation/adapters/sinatra.rb
73
+ - lib/simple_navigation/core.rb
74
+ - lib/simple_navigation/core/configuration.rb
75
+ - lib/simple_navigation/core/item.rb
76
+ - lib/simple_navigation/core/item_adapter.rb
77
+ - lib/simple_navigation/core/item_container.rb
78
+ - lib/simple_navigation/core/items_provider.rb
79
+ - lib/simple_navigation/rails_controller_methods.rb
80
+ - lib/simple_navigation/rendering.rb
81
+ - lib/simple_navigation/rendering/helpers.rb
82
+ - lib/simple_navigation/rendering/renderer/base.rb
83
+ - lib/simple_navigation/rendering/renderer/breadcrumbs.rb
84
+ - lib/simple_navigation/rendering/renderer/links.rb
85
+ - lib/simple_navigation/rendering/renderer/list.rb
69
86
  - rails/init.rb
70
- - spec/lib/simple_navigation/configuration_spec.rb
71
- - spec/lib/simple_navigation/controller_methods_spec.rb
72
- - spec/lib/simple_navigation/helpers_spec.rb
73
- - spec/lib/simple_navigation/item_adapter_spec.rb
74
- - spec/lib/simple_navigation/item_container_spec.rb
75
- - spec/lib/simple_navigation/item_spec.rb
76
- - spec/lib/simple_navigation/items_provider_spec.rb
77
- - spec/lib/simple_navigation/renderer/base_spec.rb
78
- - spec/lib/simple_navigation/renderer/breadcrumbs_spec.rb
79
- - spec/lib/simple_navigation/renderer/links_spec.rb
80
- - spec/lib/simple_navigation/renderer/list_spec.rb
87
+ - spec/lib/simple_navigation/adapters/padrino_spec.rb
88
+ - spec/lib/simple_navigation/adapters/rails_spec.rb
89
+ - spec/lib/simple_navigation/adapters/sinatra_spec.rb
90
+ - spec/lib/simple_navigation/core/configuration_spec.rb
91
+ - spec/lib/simple_navigation/core/item_adapter_spec.rb
92
+ - spec/lib/simple_navigation/core/item_container_spec.rb
93
+ - spec/lib/simple_navigation/core/item_spec.rb
94
+ - spec/lib/simple_navigation/core/items_provider_spec.rb
95
+ - spec/lib/simple_navigation/rails_controller_methods_spec.rb
96
+ - spec/lib/simple_navigation/rendering/helpers_spec.rb
97
+ - spec/lib/simple_navigation/rendering/renderer/base_spec.rb
98
+ - spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb
99
+ - spec/lib/simple_navigation/rendering/renderer/links_spec.rb
100
+ - spec/lib/simple_navigation/rendering/renderer/list_spec.rb
81
101
  - spec/lib/simple_navigation_spec.rb
82
102
  - spec/spec_helper.rb
83
103
  has_rdoc: true
@@ -91,41 +111,40 @@ rdoc_options:
91
111
  require_paths:
92
112
  - lib
93
113
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
114
  requirements:
96
115
  - - ">="
97
116
  - !ruby/object:Gem::Version
98
- hash: 3
99
117
  segments:
100
118
  - 0
101
119
  version: "0"
102
120
  required_rubygems_version: !ruby/object:Gem::Requirement
103
- none: false
104
121
  requirements:
105
122
  - - ">="
106
123
  - !ruby/object:Gem::Version
107
- hash: 3
108
124
  segments:
109
125
  - 0
110
126
  version: "0"
111
127
  requirements: []
112
128
 
113
129
  rubyforge_project: andi
114
- rubygems_version: 1.3.7
130
+ rubygems_version: 1.3.6
115
131
  signing_key:
116
132
  specification_version: 3
117
133
  summary: Simple Navigation is a ruby library for creating navigations (with multiple levels) for your Ruby on Rails application.
118
134
  test_files:
119
- - spec/lib/simple_navigation/configuration_spec.rb
120
- - spec/lib/simple_navigation/controller_methods_spec.rb
121
- - spec/lib/simple_navigation/helpers_spec.rb
122
- - spec/lib/simple_navigation/item_adapter_spec.rb
123
- - spec/lib/simple_navigation/item_container_spec.rb
124
- - spec/lib/simple_navigation/item_spec.rb
125
- - spec/lib/simple_navigation/items_provider_spec.rb
126
- - spec/lib/simple_navigation/renderer/base_spec.rb
127
- - spec/lib/simple_navigation/renderer/breadcrumbs_spec.rb
128
- - spec/lib/simple_navigation/renderer/links_spec.rb
129
- - spec/lib/simple_navigation/renderer/list_spec.rb
135
+ - spec/lib/simple_navigation/adapters/padrino_spec.rb
136
+ - spec/lib/simple_navigation/adapters/rails_spec.rb
137
+ - spec/lib/simple_navigation/adapters/sinatra_spec.rb
138
+ - spec/lib/simple_navigation/core/configuration_spec.rb
139
+ - spec/lib/simple_navigation/core/item_adapter_spec.rb
140
+ - spec/lib/simple_navigation/core/item_container_spec.rb
141
+ - spec/lib/simple_navigation/core/item_spec.rb
142
+ - spec/lib/simple_navigation/core/items_provider_spec.rb
143
+ - spec/lib/simple_navigation/rails_controller_methods_spec.rb
144
+ - spec/lib/simple_navigation/rendering/helpers_spec.rb
145
+ - spec/lib/simple_navigation/rendering/renderer/base_spec.rb
146
+ - spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb
147
+ - spec/lib/simple_navigation/rendering/renderer/links_spec.rb
148
+ - spec/lib/simple_navigation/rendering/renderer/list_spec.rb
130
149
  - spec/lib/simple_navigation_spec.rb
131
150
  - spec/spec_helper.rb
@@ -1,21 +0,0 @@
1
- module SimpleNavigation
2
- module Initializer
3
-
4
- class Rails2
5
- def self.run
6
- SimpleNavigation.rails_root = RAILS_ROOT
7
- SimpleNavigation.rails_env = RAILS_ENV
8
- SimpleNavigation.init_rails
9
- end
10
- end
11
-
12
- class Rails3
13
- def self.run
14
- SimpleNavigation.rails_root = Rails.root
15
- SimpleNavigation.rails_env = Rails.env
16
- SimpleNavigation.init_rails
17
- end
18
- end
19
-
20
- end
21
- end
@@ -1,7 +0,0 @@
1
- module SimpleNavigation
2
- class Railtie < Rails::Railtie
3
- initializer "simple_navigation.init_rails" do |app|
4
- SimpleNavigation::Initializer::Rails3.run
5
- end
6
- end
7
- end
@@ -1,90 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
4
-
5
- describe SimpleNavigation::ControllerMethods do
6
-
7
- def stub_loading_config
8
- SimpleNavigation::Configuration.stub!(:load)
9
- end
10
-
11
- before(:each) do
12
- stub_loading_config
13
- class TestController
14
- class << self
15
- def helper_method(*args)
16
- @helper_methods = args
17
- end
18
- def before_filter(*args)
19
- @before_filters = args
20
- end
21
- end
22
- end
23
- TestController.send(:include, SimpleNavigation::ControllerMethods)
24
- @controller = TestController.new
25
- end
26
-
27
- describe 'when being included' do
28
- it "should extend the ClassMethods" do
29
- @controller.class.should respond_to(:navigation)
30
- end
31
- it "should include the InstanceMethods" do
32
- @controller.should respond_to(:current_navigation)
33
- end
34
- it "should install the helper methods" do
35
- @controller.class.instance_variable_get(:@helper_methods).should == [:render_navigation, :render_primary_navigation, :render_sub_navigation]
36
- end
37
- end
38
-
39
- describe 'class_methods' do
40
-
41
- describe 'navigation' do
42
-
43
- def call_navigation(key1, key2=nil)
44
- ActiveSupport::Deprecation.silence do
45
- @controller.class_eval do
46
- navigation key1, key2
47
- end
48
- end
49
- end
50
-
51
- it "should not have an instance-method 'sn_set_navigation' if navigation-method has not been called" do
52
- @controller.respond_to?(:sn_set_navigation).should be_false
53
- end
54
- it 'should create an instance-method "sn_set_navigation" when being called' do
55
- call_navigation(:key)
56
- @controller.respond_to?(:sn_set_navigation).should be_true
57
- end
58
- it "the created method should not be public" do
59
- call_navigation(:key)
60
- @controller.public_methods.map(&:to_sym).should_not include(:sn_set_navigation)
61
- end
62
- it "the created method should be protected" do
63
- call_navigation(:key)
64
- @controller.protected_methods.map(&:to_sym).should include(:sn_set_navigation)
65
- end
66
- it 'the created method should call current_navigation with the specified keys' do
67
- call_navigation(:primary, :secondary)
68
- @controller.should_receive(:current_navigation).with(:primary, :secondary)
69
- @controller.send(:sn_set_navigation)
70
- end
71
- end
72
-
73
- end
74
-
75
- describe 'instance_methods' do
76
-
77
- describe 'current_navigation' do
78
- it "should set the sn_current_navigation_args as specified" do
79
- ActiveSupport::Deprecation.silence {@controller.current_navigation(:first)}
80
- @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first]
81
- end
82
- it "should set the sn_current_navigation_args as specified" do
83
- ActiveSupport::Deprecation.silence {@controller.current_navigation(:first, :second)}
84
- @controller.instance_variable_get(:@sn_current_navigation_args).should == [:first, :second]
85
- end
86
- end
87
-
88
- end
89
-
90
- end
@@ -1,121 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
2
- require 'html/document' unless defined? HTML::Document
3
-
4
- describe SimpleNavigation::Renderer::Links do
5
-
6
- describe 'render' do
7
-
8
-
9
- def render(current_nav=nil, options={:level => :all})
10
- primary_navigation = primary_container
11
- select_item(current_nav) if current_nav
12
- @renderer = SimpleNavigation::Renderer::Links.new(options)
13
- HTML::Document.new(@renderer.render(primary_navigation)).root
14
- end
15
-
16
- context 'regarding result' do
17
-
18
- it "should render a div-tag around the items" do
19
- HTML::Selector.new('div').select(render).should have(1).entries
20
- end
21
- it "the rendered div-tag should have the specified dom_id" do
22
- HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
23
- end
24
- it "the rendered div-tag should have the specified class" do
25
- HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
26
- end
27
- it "should render an a-tag for each item" do
28
- HTML::Selector.new('a').select(render).should have(3).entries
29
- end
30
- it "should pass the specified html_options to the a element" do
31
- HTML::Selector.new('a[style=float:right]').select(render).should have(1).entries
32
- end
33
- it "should give the a-tag the id specified in the html_options" do
34
- HTML::Selector.new('a#my_id').select(render).should have(1).entries
35
- end
36
- it "should give the a-tag the default id (stringified key) if no id is specified in the html_options" do
37
- HTML::Selector.new('a#invoices').select(render).should have(1).entries
38
- end
39
- it "should not apply the the default id where there is an id specified in the html_options" do
40
- HTML::Selector.new('a#users').select(render).should be_empty
41
- end
42
-
43
- context 'with current_navigation set' do
44
- it "should mark the matching a-item as selected (with the css_class specified in configuration)" do
45
- HTML::Selector.new('a.selected').select(render(:invoices)).should have(1).entries
46
- end
47
- end
48
-
49
- context 'without current_navigation set' do
50
- it "should not mark any of the items as selected" do
51
- HTML::Selector.new('a.selected').select(render).should be_empty
52
- end
53
- end
54
-
55
- # context 'nested sub_navigation' do
56
- # it "should nest the current_primary's subnavigation inside the selected li-element" do
57
- # HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
58
- # end
59
- # it "should be possible to identify sub items using an html selector (using ids)" do
60
- # HTML::Selector.new('#invoices #subnav1').select(render(:invoices)).should have(1).entries
61
- # end
62
- # context 'expand_all => false' do
63
- # it "should not render the invoices submenu if the user-primary is active" do
64
- # HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => false)).should be_empty
65
- # HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
66
- # end
67
- # end
68
- #
69
- # context 'expand_all => true' do
70
- # it "should render the invoices submenu even if the user-primary is active" do
71
- # HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
72
- # HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
73
- # end
74
- # end
75
- #
76
- # end
77
- end
78
-
79
- context 'regarding method calls' do
80
-
81
- context 'regarding the div_content' do
82
- before(:each) do
83
- @primary_navigation = primary_container
84
- @div_content = stub(:div_content)
85
- @div_items = stub(:div_items, :join => @div_content)
86
- @items.stub!(:inject => @div_items)
87
- @renderer = SimpleNavigation::Renderer::Links.new(options)
88
- end
89
-
90
- it "should join the list_items" do
91
- @div_items.should_receive(:join)
92
- end
93
-
94
- it "should html_saferize the list_content" do
95
- @renderer.should_receive(:html_safe).with(@div_content)
96
- end
97
-
98
- after(:each) do
99
- @renderer.render(@primary_navigation)
100
- end
101
- end
102
-
103
- context 'regarding the items' do
104
- before(:each) do
105
- @primary_navigation = primary_container
106
- @renderer = SimpleNavigation::Renderer::Links.new(options)
107
- end
108
-
109
- it "should call html_safe on every item's name" do
110
- @items.each do |item|
111
- @renderer.should_receive(:html_safe).with(item.name)
112
- end
113
- @renderer.should_receive(:html_safe).with(anything)
114
- @renderer.render(@primary_navigation)
115
- end
116
- end
117
-
118
- end
119
-
120
- end
121
- end