Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to set selected_class on container level.

  • Loading branch information...
commit 91a5503f27429ca4d781fc2b1cf8fe3a7d6adb64 1 parent a5cd097
@joost joost authored
View
3  lib/simple_navigation/core/item.rb
@@ -13,6 +13,7 @@ def initialize(container, key, name, url_or_options = {}, options_or_nil={}, ite
options = setup_url_and_options(url_or_options, options_or_nil)
@container.dom_class = options.delete(:container_class) if options[:container_class]
@container.dom_id = options.delete(:container_id) if options[:container_id]
+ @container.selected_class = options.delete(:selected_class) if options[:selected_class]
@key = key
@method = options.delete(:method)
@name = name
@@ -65,7 +66,7 @@ def active_leaf_class
# Returns the configured selected_class if the item is selected,
# nil otherwise
def selected_class
- selected? ? SimpleNavigation.config.selected_class : nil
+ selected? ? (@container.selected_class || SimpleNavigation.config.selected_class) : nil
end
protected
View
2  lib/simple_navigation/core/item_container.rb
@@ -4,7 +4,7 @@ module SimpleNavigation
class ItemContainer
attr_reader :items, :level
- attr_accessor :renderer, :dom_id, :dom_class, :auto_highlight
+ attr_accessor :renderer, :dom_id, :dom_class, :auto_highlight, :selected_class
def initialize(level=1) #:nodoc:
@level = level
View
10 spec/lib/simple_navigation/core/item_spec.rb
@@ -3,7 +3,7 @@
describe SimpleNavigation::Item do
before(:each) do
- @item_container = stub(:item_container, :level => 1).as_null_object
+ @item_container = stub(:item_container, :level => 1, :selected_class => nil).as_null_object
@item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
@adapter = stub(:adapter)
SimpleNavigation.stub!(:adapter => @adapter)
@@ -215,6 +215,14 @@
end
describe 'selected_class' do
+ context 'selected_class is defined in context' do
+ before(:each) do
+ @item_container = stub(:item_container, :level => 1, :selected_class => 'context_defined').as_null_object
+ @item = SimpleNavigation::Item.new(@item_container, :my_key, 'name', 'url', {})
+ @item.stub!(:selected? => true)
+ end
+ it {@item.instance_eval {selected_class.should == 'context_defined'}}
+ end
context 'item is selected' do
before(:each) do
@item.stub!(:selected? => true)
Please sign in to comment.
Something went wrong with that request. Please try again.