andi-simple-navigation 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ *1.1.2
2
+
3
+ * Bugfix: config now gets evaluated on every render_navigation call. Credits to Joël Azémar.
4
+ * Config file gets reloaded on every render_navigation call in development mode. Only load config file on server start in production mode.
5
+
6
+
1
7
  *1.1.1
2
8
 
3
9
  * Change plugin into a GemPlugin
data/Rakefile CHANGED
@@ -19,3 +19,47 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
19
19
  rdoc.rdoc_files.include('README')
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
+
23
+ begin
24
+ require 'jeweler'
25
+ Jeweler::Tasks.new do |gemspec|
26
+ gemspec.name = "simple-navigation"
27
+ gemspec.summary = "Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app."
28
+ gemspec.email = "andreas.schacke@gmail.com"
29
+ gemspec.homepage = "http://github.com/andi/simple-navigation"
30
+ gemspec.description = "Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app."
31
+ gemspec.authors = ["Andi Schacke"]
32
+ gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
33
+ gemspec.files += ["CHANGELOG"]
34
+ gemspec.rubyforge_project = 'andi'
35
+ end
36
+ rescue LoadError
37
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
38
+ end
39
+
40
+ begin
41
+ require 'rake/contrib/sshpublisher'
42
+ namespace :rubyforge do
43
+
44
+ desc "Release gem and RDoc documentation to RubyForge"
45
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
46
+
47
+ namespace :release do
48
+ desc "Publish RDoc to RubyForge."
49
+ task :docs => [:rdoc] do
50
+ config = YAML.load(
51
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
52
+ )
53
+
54
+ host = "#{config['username']}@rubyforge.org"
55
+ remote_dir = "/var/www/gforge-projects/andi/"
56
+ local_dir = 'rdoc'
57
+
58
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
59
+ end
60
+ end
61
+ end
62
+ rescue LoadError
63
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
64
+ end
65
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 1
4
+ :patch: 2
@@ -23,7 +23,8 @@ module SimpleNavigation
23
23
  #
24
24
  # :primary which only renders the primary_navigation (also see render_primary_navigation) and :secondary which only renders the sub_navigation (see render_sub_navigation).
25
25
  def render_navigation(level = :nested)
26
- SimpleNavigation::Configuration.eval_config(self) unless SimpleNavigation.config.loaded?
26
+ SimpleNavigation.load_config unless ::RAILS_ENV == 'production'
27
+ SimpleNavigation::Configuration.eval_config(self)
27
28
  case level
28
29
  when :primary:
29
30
  SimpleNavigation.primary_navigation.render(@current_primary_navigation)
@@ -2,10 +2,13 @@
2
2
  module SimpleNavigation
3
3
 
4
4
  mattr_accessor :config_file
5
+ mattr_accessor :config_file_path
5
6
 
6
7
  # Reads the specified config_file and stores it for later evaluation.
7
- def self.load_config(config_file)
8
- self.config_file = IO.read(config_file)
8
+ def self.load_config
9
+ raise "config_file_path is not set!" unless self.config_file_path
10
+ raise "Config file '#{config_file_path}' does not exists!" unless File.exists?(self.config_file_path)
11
+ self.config_file = IO.read(self.config_file_path)
9
12
  end
10
13
 
11
14
  # Returns the singleton instance of the SimpleNavigation::Configuration
data/rails/init.rb CHANGED
@@ -1,3 +1,4 @@
1
- config_file_path = File.join(RAILS_ROOT, 'config', 'navigation.rb')
2
- SimpleNavigation.load_config(config_file_path) if File.exists?(config_file_path)
1
+ default_config_file_path = File.join(RAILS_ROOT, 'config', 'navigation.rb')
2
+ SimpleNavigation.config_file_path = default_config_file_path unless SimpleNavigation.config_file_path
3
+ SimpleNavigation.load_config
3
4
  ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
@@ -1,29 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe SimpleNavigation do
4
-
5
- describe 'load_config' do
6
-
7
- before(:each) do
8
- @config_file = '"my_navigation_config"'
9
- IO.stub!(:read).and_return(@config_file)
10
- end
11
-
12
- it "should load the navigation-configfile into a string" do
13
- IO.should_receive(:read).with('./config/navigation.rb')
14
- SimpleNavigation.load_config('./config/navigation.rb')
15
- end
16
- it "should store that string in a module-var" do
17
- SimpleNavigation.load_config('./config/navigation.rb')
18
- SimpleNavigation.config_file.should == @config_file
19
- end
20
- end
21
-
22
- describe 'config' do
23
- it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
24
- end
25
-
26
- end
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
27
2
 
28
3
  describe SimpleNavigation::Configuration do
29
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Helpers do
4
4
  class ControllerMock
@@ -7,12 +7,61 @@ describe SimpleNavigation::Helpers do
7
7
 
8
8
  before(:each) do
9
9
  @controller = ControllerMock.new
10
- SimpleNavigation.config.stub!(:loaded?).and_return(true)
11
- @primary_navigation = stub(:primary_navigation)
10
+ SimpleNavigation.stub!(:load_config)
11
+ SimpleNavigation::Configuration.stub!(:eval_config)
12
+ @primary_navigation = stub(:primary_navigation, :null_object => true)
12
13
  SimpleNavigation.stub!(:primary_navigation).and_return(@primary_navigation)
13
14
  end
14
15
 
15
16
  describe 'render_navigation' do
17
+ describe 'regarding loading of the config-file' do
18
+ context "RAILS_ENV undefined" do
19
+ before(:each) do
20
+ ::RAILS_ENV = nil
21
+ end
22
+ it "should load the config file" do
23
+ SimpleNavigation.should_receive(:load_config)
24
+ @controller.render_navigation
25
+ end
26
+ end
27
+ context "RAILS_ENV defined" do
28
+ before(:each) do
29
+ ::RAILS_ENV = 'production'
30
+ end
31
+ context "RAILS_ENV=production" do
32
+ it "should not load the config file" do
33
+ SimpleNavigation.should_not_receive(:load_config)
34
+ @controller.render_navigation
35
+ end
36
+ end
37
+
38
+ context "RAILS_ENV=development" do
39
+ before(:each) do
40
+ ::RAILS_ENV = 'development'
41
+ end
42
+ it "should load the config file" do
43
+ SimpleNavigation.should_receive(:load_config)
44
+ @controller.render_navigation
45
+ end
46
+ end
47
+
48
+ context "RAILS_ENV=test" do
49
+ before(:each) do
50
+ ::RAILS_ENV = 'test'
51
+ end
52
+ it "should load the config file" do
53
+ SimpleNavigation.should_receive(:load_config)
54
+ @controller.render_navigation
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ it "should eval the config on every request" do
61
+ SimpleNavigation::Configuration.should_receive(:eval_config).with(@controller)
62
+ @controller.render_navigation
63
+ end
64
+
16
65
  context 'primary' do
17
66
  before(:each) do
18
67
  @controller.instance_variable_set(:@current_primary_navigation, :current_primary)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::ItemContainer do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Item do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe SimpleNavigation::Renderer::Base do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
  require 'html/document' unless defined? HTML::Document
3
3
 
4
4
  describe SimpleNavigation::Renderer::List do
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SimpleNavigation do
4
+ describe 'load_config' do
5
+ context 'config_file_path is set' do
6
+ before(:each) do
7
+ SimpleNavigation.config_file_path = 'path_to_config'
8
+ end
9
+
10
+ context 'config_file does exist' do
11
+ before(:each) do
12
+ File.stub!(:exists?).and_return(true)
13
+ IO.stub!(:read).and_return('file_content')
14
+ end
15
+ it "should not raise an error" do
16
+ lambda{SimpleNavigation.load_config}.should_not raise_error
17
+ end
18
+ it "should read the config file from disc" do
19
+ IO.should_receive(:read).with('path_to_config')
20
+ SimpleNavigation.load_config
21
+ end
22
+ it "should store the read content in the module" do
23
+ SimpleNavigation.should_receive(:config_file=).with('file_content')
24
+ SimpleNavigation.load_config
25
+ end
26
+ end
27
+
28
+ context 'config_file does not exist' do
29
+ before(:each) do
30
+ File.stub!(:exists?).and_return(false)
31
+ end
32
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
33
+ end
34
+ end
35
+
36
+ context 'config_file_path is not set' do
37
+ before(:each) do
38
+ SimpleNavigation.config_file_path = nil
39
+ end
40
+ it {lambda{SimpleNavigation.load_config}.should raise_error}
41
+ end
42
+ end
43
+
44
+ describe 'config' do
45
+ it {SimpleNavigation.config.should == SimpleNavigation::Configuration.instance}
46
+ end
47
+
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
+ RAILS_ENV = "test"
2
3
  require 'rubygems'
3
4
  require 'spec'
4
5
  require 'active_support'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: andi-simple-navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andi Schacke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-12 00:00:00 -07:00
12
+ date: 2009-04-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,17 +19,16 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
24
- files:
22
+ extra_rdoc_files:
25
23
  - README
24
+ files:
26
25
  - CHANGELOG
27
26
  - Rakefile
27
+ - VERSION.yml
28
+ - generators/navigation_config/USAGE
28
29
  - generators/navigation_config/navigation_config_generator.rb
29
30
  - generators/navigation_config/templates/config/navigation.rb
30
- - generators/navigation_config/USAGE
31
- - init.rb
32
- - install.rb
31
+ - lib/simple_navigation.rb
33
32
  - lib/simple_navigation/configuration.rb
34
33
  - lib/simple_navigation/controller_methods.rb
35
34
  - lib/simple_navigation/helpers.rb
@@ -37,17 +36,17 @@ files:
37
36
  - lib/simple_navigation/item_container.rb
38
37
  - lib/simple_navigation/renderer/base.rb
39
38
  - lib/simple_navigation/renderer/list.rb
40
- - lib/simple_navigation.rb
41
39
  - rails/init.rb
42
- - spec/lib/configuration_spec.rb
43
- - spec/lib/controller_methods_spec.rb
44
- - spec/lib/helpers_spec.rb
45
- - spec/lib/item_container_spec.rb
46
- - spec/lib/item_spec.rb
47
- - spec/lib/renderer/base_spec.rb
48
- - spec/lib/renderer/list_spec.rb
40
+ - spec/lib/simple_navigation/configuration_spec.rb
41
+ - spec/lib/simple_navigation/controller_methods_spec.rb
42
+ - spec/lib/simple_navigation/helpers_spec.rb
43
+ - spec/lib/simple_navigation/item_container_spec.rb
44
+ - spec/lib/simple_navigation/item_spec.rb
45
+ - spec/lib/simple_navigation/renderer/base_spec.rb
46
+ - spec/lib/simple_navigation/renderer/list_spec.rb
47
+ - spec/lib/simple_navigation_spec.rb
49
48
  - spec/spec_helper.rb
50
- - uninstall.rb
49
+ - README
51
50
  has_rdoc: true
52
51
  homepage: http://github.com/andi/simple-navigation
53
52
  post_install_message:
@@ -70,10 +69,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
69
  version:
71
70
  requirements: []
72
71
 
73
- rubyforge_project:
72
+ rubyforge_project: andi
74
73
  rubygems_version: 1.2.0
75
74
  signing_key:
76
75
  specification_version: 2
77
76
  summary: Simple Navigation is a ruby library for creating a navigation (optionally with sub navigation) for your rails app.
78
- test_files: []
79
-
77
+ test_files:
78
+ - spec/lib/simple_navigation/configuration_spec.rb
79
+ - spec/lib/simple_navigation/controller_methods_spec.rb
80
+ - spec/lib/simple_navigation/helpers_spec.rb
81
+ - spec/lib/simple_navigation/item_container_spec.rb
82
+ - spec/lib/simple_navigation/item_spec.rb
83
+ - spec/lib/simple_navigation/renderer/base_spec.rb
84
+ - spec/lib/simple_navigation/renderer/list_spec.rb
85
+ - spec/lib/simple_navigation_spec.rb
86
+ - spec/spec_helper.rb
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/rails/init"
data/install.rb DELETED
@@ -1,5 +0,0 @@
1
- begin
2
- puts IO.read(File.join(File.dirname(__FILE__), 'README'))
3
- rescue Exception => e
4
- puts "The following error ocurred while installing the plugin: #{e.message}"
5
- end
data/uninstall.rb DELETED
@@ -1 +0,0 @@
1
- # Uninstall hook code here