simple-navigation 2.2.3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *2.4.0
2
+
3
+ * added Rails3 compatibility
4
+ * added Jeweler::Gemcutter Tasks to Rakefile
5
+
1
6
  *2.2.3
2
7
 
3
8
  * changed error handling in config-file. Do not ignore errors in config-file anymore.
data/Rakefile CHANGED
@@ -38,11 +38,14 @@ begin
38
38
  gemspec.email = "andreas.schacke@gmail.com"
39
39
  gemspec.homepage = "http://github.com/andi/simple-navigation"
40
40
  gemspec.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."
41
+ gemspec.add_dependency('rails', '>= 2.1.0')
42
+ gemspec.add_development_dependency('rspec', '>= 1.2.8')
41
43
  gemspec.authors = ["Andi Schacke"]
42
44
  gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
43
45
  gemspec.files = FileList["[A-Z]*", "{lib,spec,rails,generators}/**/*"] - FileList["**/*.log"]
44
46
  gemspec.rubyforge_project = 'andi'
45
47
  end
48
+ Jeweler::GemcutterTasks.new
46
49
  Jeweler::RubyforgeTasks.new do |rubyforge|
47
50
  rubyforge.doc_task = "rdoc"
48
51
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
- :minor: 2
4
- :patch: 3
3
+ :minor: 4
4
+ :patch: 0
@@ -8,15 +8,26 @@ require 'simple_navigation/item_container'
8
8
  require 'simple_navigation/items_provider'
9
9
  require 'simple_navigation/renderer/base'
10
10
  require 'simple_navigation/renderer/list'
11
+ require 'simple_navigation/initializer'
12
+ require 'simple_navigation/railtie' if Rails::VERSION::MAJOR == 3
11
13
 
12
14
  # A plugin for generating a simple navigation. See README for resources on usage instructions.
13
15
  module SimpleNavigation
14
16
 
15
- mattr_accessor :config_files, :config_file_path, :controller, :template, :explicit_current_navigation
17
+ mattr_accessor :config_files, :config_file_path, :controller, :template, :explicit_current_navigation, :rails_env, :rails_root
16
18
 
17
19
  self.config_files = {}
18
20
 
19
21
  class << self
22
+
23
+ def init_rails
24
+ SimpleNavigation.config_file_path = SimpleNavigation.default_config_file_path unless SimpleNavigation.config_file_path
25
+ ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
26
+ end
27
+
28
+ def default_config_file_path
29
+ File.join(SimpleNavigation.rails_root, 'config')
30
+ end
20
31
 
21
32
  def config_file?(navigation_context=nil)
22
33
  File.exists?(config_file_name(navigation_context))
@@ -26,7 +37,7 @@ module SimpleNavigation
26
37
  def load_config(navigation_context = :default)
27
38
  raise "config_file_path is not set!" unless self.config_file_path
28
39
  raise "Config file '#{config_file_name(navigation_context)}' does not exists!" unless config_file?(navigation_context)
29
- if ::RAILS_ENV == 'production'
40
+ if SimpleNavigation.rails_env == 'production'
30
41
  self.config_files[navigation_context] ||= IO.read(config_file_name(navigation_context))
31
42
  else
32
43
  self.config_files[navigation_context] = IO.read(config_file_name(navigation_context))
@@ -146,6 +157,7 @@ module SimpleNavigation
146
157
  end
147
158
 
148
159
  # TODOs for the next releases:
160
+ # 0) make sn_set_navigation private in controllers
149
161
  # 1) add ability to specify explicit highlighting in the config-file itself (directly with the item)
150
162
  # - item.highlight_on :controller => 'users', :action => 'show' ...^
151
163
  # --> with that we can get rid of the controller_methods...
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,9 @@
1
+ module SimpleNavigation
2
+ class Railtie < Rails::Railtie
3
+ railtie_name :simple_navigation
4
+
5
+ initializer "simple_navigation.init_rails" do |app|
6
+ SimpleNavigation::Initializer::Rails3.run
7
+ end
8
+ end
9
+ end
data/rails/init.rb CHANGED
@@ -1,3 +1,5 @@
1
- default_config_file_path = File.join(RAILS_ROOT, 'config')
2
- SimpleNavigation.config_file_path = default_config_file_path unless SimpleNavigation.config_file_path
3
- ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
1
+ if Rails::VERSION::MAJOR == 3
2
+ SimpleNavigation::Initializer::Rails3.run
3
+ else
4
+ SimpleNavigation::Initializer::Rails2.run
5
+ end
@@ -10,9 +10,18 @@ describe SimpleNavigation::ControllerMethods do
10
10
 
11
11
  before(:each) do
12
12
  stub_loading_config
13
- class ApplicationController < ActionController::Base
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
14
22
  end
15
- @controller = ApplicationController.new
23
+ TestController.send(:include, SimpleNavigation::ControllerMethods)
24
+ @controller = TestController.new
16
25
  end
17
26
 
18
27
  describe 'when being included' do
@@ -22,10 +31,8 @@ describe SimpleNavigation::ControllerMethods do
22
31
  it "should include the InstanceMethods" do
23
32
  @controller.should respond_to(:current_navigation)
24
33
  end
25
- it "should install the Helpers Module" do
26
- [:render_navigation, :render_primary_navigation, :render_sub_navigation].each do |m|
27
- @controller.master_helper_module.instance_methods.map(&:to_s).should include(m.to_s)
28
- 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]
29
36
  end
30
37
  end
31
38
 
@@ -73,6 +73,39 @@ describe SimpleNavigation do
73
73
  end
74
74
  end
75
75
 
76
+ describe 'self.init_rails' do
77
+ before(:each) do
78
+ SimpleNavigation.stub!(:default_config_file_path => 'default_path')
79
+ ActionController::Base.stub!(:include)
80
+ end
81
+ context 'SimpleNavigation.config_file_path is already set' do
82
+ before(:each) do
83
+ SimpleNavigation.config_file_path = 'my_path'
84
+ end
85
+ it "should not override the config_file_path" do
86
+ SimpleNavigation.init_rails
87
+ SimpleNavigation.config_file_path.should == 'my_path'
88
+ end
89
+ end
90
+ context 'SimpleNavigation.config_file_path is not set' do
91
+ before(:each) do
92
+ SimpleNavigation.config_file_path = nil
93
+ end
94
+ it "should set the config_file_path to the default" do
95
+ SimpleNavigation.init_rails
96
+ SimpleNavigation.config_file_path.should == 'default_path'
97
+ end
98
+ end
99
+ it "should extend the ActionController::Base" do
100
+ ActionController::Base.should_receive(:include).with(SimpleNavigation::ControllerMethods)
101
+ SimpleNavigation.init_rails
102
+ end
103
+ end
104
+
105
+ describe 'self.default_config_file_path' do
106
+ it {SimpleNavigation.default_config_file_path.should == './config'}
107
+ end
108
+
76
109
  describe 'self.extract_controller_from' do
77
110
  before(:each) do
78
111
  @nav_context = stub(:nav_context)
@@ -192,7 +225,7 @@ describe SimpleNavigation do
192
225
  end
193
226
  context "RAILS_ENV undefined" do
194
227
  before(:each) do
195
- ::RAILS_ENV = nil
228
+ SimpleNavigation.rails_env = nil
196
229
  end
197
230
  it "should load the config file twice" do
198
231
  IO.should_receive(:read).twice
@@ -202,7 +235,7 @@ describe SimpleNavigation do
202
235
  end
203
236
  context "RAILS_ENV defined" do
204
237
  before(:each) do
205
- ::RAILS_ENV = 'production'
238
+ SimpleNavigation.rails_env = 'production'
206
239
  end
207
240
  context "RAILS_ENV=production" do
208
241
  it "should load the config file only once" do
@@ -214,7 +247,7 @@ describe SimpleNavigation do
214
247
 
215
248
  context "RAILS_ENV=development" do
216
249
  before(:each) do
217
- ::RAILS_ENV = 'development'
250
+ SimpleNavigation.rails_env = 'development'
218
251
  end
219
252
  it "should load the config file twice" do
220
253
  IO.should_receive(:read).twice
@@ -225,7 +258,7 @@ describe SimpleNavigation do
225
258
 
226
259
  context "RAILS_ENV=test" do
227
260
  before(:each) do
228
- ::RAILS_ENV = 'test'
261
+ SimpleNavigation.rails_env = 'test'
229
262
  end
230
263
  it "should load the config file twice" do
231
264
  IO.should_receive(:read).twice
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,22 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
- RAILS_ENV = "test" unless defined? RAILS_ENV
3
2
  require 'rubygems'
4
3
  require 'spec'
5
4
  require 'active_support'
6
5
  require 'action_controller'
7
6
 
8
- RAILS_ROOT = './' unless defined? RAILS_ROOT
7
+ module Rails
8
+ module VERSION
9
+ MAJOR = 2
10
+ end
11
+ end unless defined? Rails
9
12
 
10
13
  $:.unshift File.dirname(__FILE__)
11
14
  $:.unshift File.join(File.dirname(__FILE__), '../lib')
12
15
 
13
16
  require 'simple_navigation'
14
17
 
18
+ SimpleNavigation.rails_root = './'
19
+
15
20
  # Spec::Runner.configure do |config|
16
21
  # no special config
17
22
  # endx
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andi Schacke
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-21 00:00:00 +01:00
12
+ date: 2010-03-01 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.8
34
+ version:
16
35
  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.
17
36
  email: andreas.schacke@gmail.com
18
37
  executables: []
@@ -34,10 +53,12 @@ files:
34
53
  - lib/simple_navigation/configuration.rb
35
54
  - lib/simple_navigation/controller_methods.rb
36
55
  - lib/simple_navigation/helpers.rb
56
+ - lib/simple_navigation/initializer.rb
37
57
  - lib/simple_navigation/item.rb
38
58
  - lib/simple_navigation/item_adapter.rb
39
59
  - lib/simple_navigation/item_container.rb
40
60
  - lib/simple_navigation/items_provider.rb
61
+ - lib/simple_navigation/railtie.rb
41
62
  - lib/simple_navigation/renderer/base.rb
42
63
  - lib/simple_navigation/renderer/list.rb
43
64
  - rails/init.rb