simple-navigation 3.9.0 → 3.10.0

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
+ *3.10.0
2
+
3
+ * Added ability to set selected_class on container level. Credits to Joost Hietbrink.
4
+ * do not highlight items that are only partial matches. Thanks to Troy Thompson.
5
+ * adding support for rails 4. Credits to Samer Masry.
6
+
1
7
  *3.9.0
2
8
 
3
9
  * Added ability to pass a block to render_navigation for configuring dynamic navigation items (instead of passing :items). Credits to Ronald Chan.
data/Gemfile CHANGED
@@ -12,4 +12,5 @@ group :development do
12
12
  gem 'rspec', '>= 2.0.1'
13
13
  gem 'rake'
14
14
  gem 'rdoc'
15
+ gem 'jeweler'
15
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.9.0
1
+ 3.10.0
@@ -49,15 +49,15 @@ module SimpleNavigation
49
49
  protected
50
50
 
51
51
  def self.rails_root
52
- rails3? ? ::Rails.root : ::RAILS_ROOT
52
+ gte_rails3? ? ::Rails.root : ::RAILS_ROOT
53
53
  end
54
54
 
55
55
  def self.rails_env
56
- rails3? ? ::Rails.env : ::RAILS_ENV
56
+ gte_rails3? ? ::Rails.env : ::RAILS_ENV
57
57
  end
58
58
 
59
- def self.rails3?
60
- ::Rails::VERSION::MAJOR == 3
59
+ def self.gte_rails3?
60
+ ::Rails::VERSION::MAJOR >= 3
61
61
  end
62
62
 
63
63
  def template_from(controller)
@@ -82,7 +82,7 @@ module SimpleNavigation
82
82
  end
83
83
 
84
84
  # Initializer for Rails3
85
- if defined?(Rails) && Rails::VERSION::MAJOR == 3
85
+ if defined?(Rails) && SimpleNavigation::Adapters::Rails.gte_rails3?
86
86
  module SimpleNavigation
87
87
  class Railtie < Rails::Railtie
88
88
  initializer "simple_navigation.register" do |app|
@@ -13,6 +13,7 @@ module SimpleNavigation
13
13
  options = setup_url_and_options(url_or_options, options_or_nil)
14
14
  @container.dom_class = options.delete(:container_class) if options[:container_class]
15
15
  @container.dom_id = options.delete(:container_id) if options[:container_id]
16
+ @container.selected_class = options.delete(:selected_class) if options[:selected_class]
16
17
  @key = key
17
18
  @method = options.delete(:method)
18
19
  @name = name
@@ -65,7 +66,7 @@ module SimpleNavigation
65
66
  # Returns the configured selected_class if the item is selected,
66
67
  # nil otherwise
67
68
  def selected_class
68
- selected? ? SimpleNavigation.config.selected_class : nil
69
+ selected? ? (@container.selected_class || SimpleNavigation.config.selected_class) : nil
69
70
  end
70
71
 
71
72
  protected
@@ -88,7 +89,7 @@ module SimpleNavigation
88
89
  when Proc
89
90
  highlights_on.call
90
91
  when :subpath
91
- !!(SimpleNavigation.request_uri =~ /^#{Regexp.escape url_without_anchor}/)
92
+ !!(SimpleNavigation.request_uri =~ /^#{Regexp.escape url_without_anchor}(\/|$|\?)/i)
92
93
  else
93
94
  raise ArgumentError, ':highlights_on must be a Regexp, Proc or :subpath'
94
95
  end
@@ -4,7 +4,7 @@ module SimpleNavigation
4
4
  class ItemContainer
5
5
 
6
6
  attr_reader :items, :level
7
- attr_accessor :renderer, :dom_id, :dom_class, :auto_highlight
7
+ attr_accessor :renderer, :dom_id, :dom_class, :auto_highlight, :selected_class
8
8
 
9
9
  def initialize(level=1) #:nodoc:
10
10
  @level = level
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe SimpleNavigation::Item do
4
4
 
5
5
  before(:each) do
6
- @item_container = stub(:item_container, :level => 1).as_null_object
6
+ @item_container = stub(:item_container, :level => 1, :selected_class => nil).as_null_object
7
7
  @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
8
8
  @adapter = stub(:adapter)
9
9
  SimpleNavigation.stub!(:adapter => @adapter)
@@ -215,6 +215,14 @@ describe SimpleNavigation::Item do
215
215
  end
216
216
 
217
217
  describe 'selected_class' do
218
+ context 'selected_class is defined in context' do
219
+ before(:each) do
220
+ @item_container = stub(:item_container, :level => 1, :selected_class => 'context_defined').as_null_object
221
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
222
+ @item.stub!(:selected? => true)
223
+ end
224
+ it {@item.instance_eval {selected_class.should == 'context_defined'}}
225
+ end
218
226
  context 'item is selected' do
219
227
  before(:each) do
220
228
  @item.stub!(:selected? => true)
@@ -389,6 +397,12 @@ describe SimpleNavigation::Item do
389
397
  end
390
398
  it {@item.send(:selected_by_condition?).should be_true}
391
399
  end
400
+ context 'we are in a route that has a similar name' do
401
+ before(:each) do
402
+ SimpleNavigation.stub!(:request_uri => '/resources_group/id')
403
+ end
404
+ it {@item.send(:selected_by_condition?).should be_false}
405
+ end
392
406
  context 'we are in a route not beginning with this item path' do
393
407
  before(:each) do
394
408
  SimpleNavigation.stub!(:request_uri => '/another_resource/id')
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: 3.9.0
4
+ version: 3.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-02 00:00:00.000000000 Z
13
+ date: 2013-01-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -76,6 +76,22 @@ dependencies:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: jeweler
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
79
95
  description: With the simple-navigation gem installed you can easily create multilevel
80
96
  navigations for your Rails, Sinatra or Padrino applications. The navigation is defined
81
97
  in a single configuration file. It supports automatic as well as explicit highlighting