simple-navigation 3.0.0 → 3.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ *3.0.1
2
+
3
+ * allow controller instance variables named @template for rails3 apps. Credits to cmartyn.
4
+ * added possibility to specify and item's URL as a block which is evaulated after the :if and :unless conditions have been checked. Credits to Nicholas Firth-McCoy.
5
+ * upgraded to rspec 2.0.0
6
+ * fixed cgi error in sinatra adapter. Credits to Jack Dempsey.
7
+
1
8
  *3.0.0
2
9
 
3
10
  * added ability to specify dynamic items using an array of hashes. Credits to Anshul Khandelwal for input and discussion.
data/Rakefile CHANGED
@@ -1,21 +1,19 @@
1
1
  require 'rake'
2
- require 'spec/rake/spectask'
2
+ require 'rspec/core/rake_task'
3
3
  require 'rake/rdoctask'
4
4
 
5
5
  desc 'Default: run specs.'
6
6
  task :default => :spec
7
7
 
8
8
  desc 'Run the specs'
9
- Spec::Rake::SpecTask.new(:spec) do |t|
10
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
11
- t.spec_files = FileList['spec/**/*_spec.rb']
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ t.rspec_opts = ['--colour --format progress']
12
11
  end
13
12
 
14
13
  namespace :spec do
15
14
  desc "Run all specs with RCov"
16
- Spec::Rake::SpecTask.new(:rcov) do |t|
17
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
18
- t.spec_files = FileList['spec/**/*_spec.rb']
15
+ RSpec::Core::RakeTask.new(:rcov) do |t|
16
+ t.rspec_opts = ['--colour --format progress']
19
17
  t.rcov = true
20
18
  t.rcov_opts = ['--exclude', 'spec,/Users/']
21
19
  end
@@ -38,7 +36,7 @@ begin
38
36
  gemspec.email = "andreas.schacke@gmail.com"
39
37
  gemspec.homepage = "http://github.com/andi/simple-navigation"
40
38
  gemspec.description = "With the simple-navigation gem installed you can easily create multilevel navigations for your Rails, Sinatra or Padrino applications. The navigation is defined in a single configuration file. It supports automatic as well as explicit highlighting of the currently active navigation through regular expressions."
41
- gemspec.add_development_dependency('rspec', '>= 1.2.8')
39
+ gemspec.add_development_dependency('rspec', '>= 2.0.1')
42
40
  gemspec.add_dependency('activesupport', '>= 2.3.2')
43
41
  gemspec.authors = ["Andi Schacke"]
44
42
  gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.1
@@ -59,7 +59,7 @@ module SimpleNavigation
59
59
  end
60
60
 
61
61
  def template_from(controller)
62
- controller.instance_variable_get(:@template) || (controller.respond_to?(:view_context) ? controller.view_context : nil)
62
+ controller.respond_to?(:view_context) ? controller.view_context : controller.instance_variable_get(:@template)
63
63
  end
64
64
 
65
65
  # Marks the specified input as html_safe (for Rails3). Does nothing if html_safe is not defined on input.
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module SimpleNavigation
2
4
  module Adapters
3
5
  class Sinatra < Base
@@ -13,7 +13,7 @@ module SimpleNavigation
13
13
  @key = key
14
14
  @method = options.delete(:method)
15
15
  @name = name
16
- @url = url
16
+ @url = url.instance_of?(Proc) ? url.call : url
17
17
  @highlights_on = options.delete(:highlights_on)
18
18
  @html_options = options
19
19
  if sub_nav_block || items
@@ -11,7 +11,6 @@ module SimpleNavigation
11
11
  class Breadcrumbs < SimpleNavigation::Renderer::Base
12
12
 
13
13
  def render(item_container)
14
- a_tags = a_tags(item_container)
15
14
  content_tag(:div, a_tags(item_container).join(join_with), {:id => item_container.dom_id, :class => item_container.dom_class})
16
15
  end
17
16
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Adapters::Padrino do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Adapters::Rails do
4
4
 
@@ -265,5 +265,19 @@ describe SimpleNavigation::Adapters::Rails do
265
265
  end
266
266
  end
267
267
 
268
+ describe 'template_from' do
269
+ context 'Rails3' do
270
+ before(:each) do
271
+ @controller.stub!(:view_context => 'view')
272
+ end
273
+ it {@adapter.send(:template_from, @controller).should == 'view'}
274
+ end
275
+ context 'Rails2' do
276
+ before(:each) do
277
+ @controller.instance_variable_set(:@template, 'view')
278
+ end
279
+ it {@adapter.send(:template_from, @controller).should == 'view'}
280
+ end
281
+ end
268
282
 
269
283
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Adapters::Sinatra do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Configuration do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::ItemAdapter, 'when item is an object' do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::ItemContainer do
4
4
  before(:each) do
@@ -19,7 +19,7 @@ describe SimpleNavigation::ItemContainer do
19
19
  before(:each) do
20
20
  @item = stub(:item)
21
21
  @items = [@item]
22
- @item_adapter = stub(:item_adapter, :null_object => true)
22
+ @item_adapter = stub(:item_adapter).as_null_object
23
23
  SimpleNavigation::ItemAdapter.stub(:new => @item_adapter)
24
24
  @item_container.stub!(:should_add_item? => true)
25
25
  end
@@ -290,7 +290,7 @@ describe SimpleNavigation::ItemContainer do
290
290
 
291
291
  describe 'render' do
292
292
  before(:each) do
293
- @renderer_instance = stub(:renderer, :null_object => true)
293
+ @renderer_instance = stub(:renderer).as_null_object
294
294
  @renderer_class = stub(:renderer_class, :new => @renderer_instance)
295
295
  end
296
296
  context 'renderer specified as option' do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Item do
4
4
 
@@ -12,7 +12,7 @@ describe SimpleNavigation::Item do
12
12
  describe 'initialize' do
13
13
  context 'subnavigation' do
14
14
  before(:each) do
15
- @subnav_container = stub(:subnav_container, :null_object => true)
15
+ @subnav_container = stub(:subnav_container).as_null_object
16
16
  SimpleNavigation::ItemContainer.stub!(:new => @subnav_container)
17
17
  end
18
18
  context 'block given' do
@@ -89,6 +89,22 @@ describe SimpleNavigation::Item do
89
89
  end
90
90
  end
91
91
  end
92
+
93
+ context 'url' do
94
+ context 'url is a string' do
95
+ before(:each) do
96
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
97
+ end
98
+ it {@item.url.should == 'url'}
99
+ end
100
+ context 'url is a proc' do
101
+ before(:each) do
102
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', Proc.new {"my_" + "url"}, {})
103
+ end
104
+ it {@item.url.should == 'my_url'}
105
+ end
106
+ end
107
+
92
108
  end
93
109
 
94
110
  describe 'selected?' do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::ItemsProvider do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'explicit navigation in rails' do
4
4
  require 'simple_navigation/rails_controller_methods'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Helpers do
4
4
  class ControllerMock
@@ -9,7 +9,7 @@ describe SimpleNavigation::Helpers do
9
9
  @controller = ControllerMock.new
10
10
  SimpleNavigation.stub!(:load_config)
11
11
  SimpleNavigation::Configuration.stub!(:eval_config)
12
- @primary_navigation = stub(:primary_navigation, :null_object => true)
12
+ @primary_navigation = stub(:primary_navigation).as_null_object
13
13
  SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
14
14
  SimpleNavigation.stub!(:config_file? => true)
15
15
  end
@@ -64,7 +64,7 @@ describe SimpleNavigation::Helpers do
64
64
 
65
65
  context 'rendering of the item_container' do
66
66
  before(:each) do
67
- @active_item_container = stub(:item_container, :null_object => true)
67
+ @active_item_container = stub(:item_container).as_null_object
68
68
  SimpleNavigation.stub!(:active_item_container_for => @active_item_container)
69
69
  end
70
70
  it "should lookup the active_item_container based on the level" do
@@ -98,7 +98,7 @@ describe SimpleNavigation::Helpers do
98
98
  context 'secondary' do
99
99
  context 'with current_primary_navigation set' do
100
100
  before(:each) do
101
- @selected_item_container = stub(:selected_container, :null_object => true)
101
+ @selected_item_container = stub(:selected_container).as_null_object
102
102
  SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
103
103
  end
104
104
  it "should find the selected sub_navigation for the specified level" do
@@ -134,7 +134,7 @@ describe SimpleNavigation::Helpers do
134
134
 
135
135
  describe "should treat :level and :levels options the same" do
136
136
  before(:each) do
137
- @selected_item_container = stub(:selected_container, :null_object => true)
137
+ @selected_item_container = stub(:selected_container).as_null_object
138
138
  SimpleNavigation.stub!(:active_item_container_for => @selected_item_container)
139
139
  end
140
140
  it "should pass a valid levels options as level" do
@@ -1,8 +1,8 @@
1
- require File.dirname(__FILE__) + '/../../../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Renderer::Base do
4
4
  before(:each) do
5
- @options = stub(:options, :null_object => true)
5
+ @options = stub(:options).as_null_object
6
6
  @adapter = stub(:adapter)
7
7
  SimpleNavigation.stub!(:adapter => @adapter)
8
8
  @base_renderer = SimpleNavigation::Renderer::Base.new(@options)
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../../../../spec_helper'
2
- require 'html/document' unless defined? HTML::Document
1
+ require 'spec_helper'
2
+ require 'html/document'# unless defined? HTML::Document
3
3
 
4
4
  describe SimpleNavigation::Renderer::Breadcrumbs do
5
5
 
@@ -15,23 +15,23 @@ describe SimpleNavigation::Renderer::Breadcrumbs do
15
15
  context 'regarding result' do
16
16
 
17
17
  it "should render a div-tag around the items" do
18
- HTML::Selector.new('div').select(render).should have(1).entries
19
- end
20
- it "the rendered div-tag should have the specified dom_id" do
21
- HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
22
- end
23
- it "the rendered div-tag should have the specified class" do
24
- HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
25
- end
26
-
27
- context 'without current_navigation set' do
28
- it "should not render any a-tag in the div-tag" do
29
- HTML::Selector.new('div a').select(render).should have(0).entries
18
+ HTML::Selector.new('div').select(render).should have(1).entries
19
+ end
20
+ it "the rendered div-tag should have the specified dom_id" do
21
+ HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
22
+ end
23
+ it "the rendered div-tag should have the specified class" do
24
+ HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
25
+ end
26
+
27
+ context 'without current_navigation set' do
28
+ it "should not render any a-tag in the div-tag" do
29
+ HTML::Selector.new('div a').select(render).should have(0).entries
30
+ end
30
31
  end
31
- end
32
32
 
33
33
  context 'with current_navigation set' do
34
- before :all do
34
+ before(:each) do
35
35
  @selection = HTML::Selector.new('div a').select(render(:invoices))
36
36
  end
37
37
  it "should render the selected a tags" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'html/document' unless defined? HTML::Document
3
3
 
4
4
  describe SimpleNavigation::Renderer::Links do
@@ -6,7 +6,6 @@ describe SimpleNavigation::Renderer::Links do
6
6
 
7
7
  describe 'render' do
8
8
 
9
-
10
9
  def render(current_nav=nil, options={:level => :all})
11
10
  primary_navigation = primary_container
12
11
  select_item(current_nav) if current_nav
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../../spec_helper'
1
+ require 'spec_helper'
2
2
  require 'html/document' unless defined? HTML::Document
3
3
 
4
4
  describe SimpleNavigation::Renderer::List do
@@ -145,7 +145,7 @@ describe SimpleNavigation::Renderer::List do
145
145
 
146
146
  describe 'link_options_for' do
147
147
  before(:each) do
148
- setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
148
+ setup_renderer_for SimpleNavigation::Renderer::List, :rails, {}
149
149
  end
150
150
  context 'no link options specified' do
151
151
  context 'method specified' do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SimpleNavigation do
4
4
 
@@ -1,6 +1,6 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
2
  require 'rubygems'
3
- require 'spec'
3
+ require 'rspec'
4
4
  require 'action_controller'
5
5
 
6
6
  module Rails
@@ -19,9 +19,17 @@ RAILS_ROOT = './' unless defined?(RAILS_ROOT)
19
19
  RAILS_ENV = 'test' unless defined?(RAILS_ENV)
20
20
 
21
21
 
22
- # Spec::Runner.configure do |config|
23
- # no special config
24
- # end
22
+ RSpec.configure do |config|
23
+ # == Mock Framework
24
+ #
25
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
26
+ #
27
+ # config.mock_with :mocha
28
+ # config.mock_with :flexmock
29
+ # config.mock_with :rr
30
+ config.mock_with :rspec
31
+
32
+ end
25
33
 
26
34
  # spec helper methods
27
35
  def sub_items
@@ -60,9 +68,9 @@ def select_item(key)
60
68
  primary_item(:invoices) do |item|
61
69
  item.instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}.stub!(:selected? => true)
62
70
  end
63
-
71
+ else
72
+ primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
64
73
  end
65
- primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
66
74
  end
67
75
 
68
76
  def subnav_container
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 5
4
5
  prerelease: false
5
6
  segments:
6
7
  - 3
7
8
  - 0
8
- - 0
9
- version: 3.0.0
9
+ - 1
10
+ version: 3.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Andi Schacke
@@ -14,30 +15,34 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-28 00:00:00 +02:00
18
+ date: 2010-10-26 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
- - 1
29
31
  - 2
30
- - 8
31
- version: 1.2.8
32
+ - 0
33
+ - 1
34
+ version: 2.0.1
32
35
  type: :development
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: activesupport
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 7
41
46
  segments:
42
47
  - 2
43
48
  - 3
@@ -110,23 +115,27 @@ rdoc_options:
110
115
  require_paths:
111
116
  - lib
112
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
113
119
  requirements:
114
120
  - - ">="
115
121
  - !ruby/object:Gem::Version
122
+ hash: 3
116
123
  segments:
117
124
  - 0
118
125
  version: "0"
119
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
120
128
  requirements:
121
129
  - - ">="
122
130
  - !ruby/object:Gem::Version
131
+ hash: 3
123
132
  segments:
124
133
  - 0
125
134
  version: "0"
126
135
  requirements: []
127
136
 
128
137
  rubyforge_project: andi
129
- rubygems_version: 1.3.6
138
+ rubygems_version: 1.3.7
130
139
  signing_key:
131
140
  specification_version: 3
132
141
  summary: simple-navigation is a ruby library for creating navigations (with multiple levels) for your Rails2, Rails3, Sinatra or Padrino application.