Permalink
Browse files

Merge pull request #114 from joost/master

Ability to set selected_class on container (useful for dynamic navigation)
  • Loading branch information...
andi committed Nov 26, 2012
2 parents a5cd097 + 91a5503 commit 7f659a780476cd68807ff1a718449ea9c28df08d
@@ -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
@@ -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
@@ -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)

0 comments on commit 7f659a7

Please sign in to comment.