diff --git a/lib/simple_navigation/renderer/list.rb b/lib/simple_navigation/renderer/list.rb
index f8927457..668a9549 100644
--- a/lib/simple_navigation/renderer/list.rb
+++ b/lib/simple_navigation/renderer/list.rb
@@ -4,29 +4,24 @@ module Renderer
# Renders an ItemContainer as a
element and its containing items as - elements.
# It adds the 'selected' class to li element AND the link inside the li element that is currently active.
#
- # If the sub navigation should be included, it renders another
containing the sub navigation inside the active - element.
- #
- # If the SimpleNavigation.config.render_all_levels option is set to true, it always renders all levels of navigation (fully expanded tree).
+ # If the sub navigation should be included (based on the level and expand_all options), it renders another
containing the sub navigation inside the active - element.
#
# By default, the renderer sets the item's key as dom_id for the rendered
- element unless the config option autogenerate_item_ids is set to false.
# The id can also be explicitely specified by setting the id in the html-options of the 'item' method in the config/navigation.rb file.
class List < SimpleNavigation::Renderer::Base
- def render(item_container, include_sub_navigation=false, max_level = nil)
+ def render(item_container)
list_content = item_container.items.inject([]) do |list, item|
html_options = item.html_options
li_content = link_to(item.name, item.url, :class => item.selected_class, :method => item.method)
- if item.sub_navigation
- if SimpleNavigation.config.render_all_levels || (include_sub_navigation && item.selected?)
- # li_content << (item.sub_navigation.render(include_sub_navigation))
- li_content << (item.sub_navigation.render(include_sub_navigation, max_level)) unless !max_level.nil? && (item.sub_navigation.level > max_level)
- end
+ if include_sub_navigation?(item)
+ li_content << render_sub_navigation_for(item)
end
list << content_tag(:li, li_content, html_options)
end
content_tag(:ul, list_content.join, {:id => item_container.dom_id, :class => item_container.dom_class})
end
-
end
+
end
-end
\ No newline at end of file
+end
diff --git a/spec/lib/simple_navigation/renderer/list_spec.rb b/spec/lib/simple_navigation/renderer/list_spec.rb
index 66bb5bdb..611af858 100644
--- a/spec/lib/simple_navigation/renderer/list_spec.rb
+++ b/spec/lib/simple_navigation/renderer/list_spec.rb
@@ -47,11 +47,11 @@ def subnav_container
container
end
- def render(current_nav=nil, include_subnav=false)
+ def render(current_nav=nil, options={:level => :all})
primary_navigation = primary_container
select_item(current_nav) if current_nav
- @renderer = SimpleNavigation::Renderer::List.new
- HTML::Document.new(@renderer.render(primary_navigation, include_subnav)).root
+ @renderer = SimpleNavigation::Renderer::List.new(options)
+ HTML::Document.new(@renderer.render(primary_navigation)).root
end
it "should render a ul-tag around the items" do
@@ -103,31 +103,25 @@ def render(current_nav=nil, include_subnav=false)
context 'nested sub_navigation' do
it "should nest the current_primary's subnavigation inside the selected li-element" do
- HTML::Selector.new('li.selected ul li').select(render(:invoices, true)).should have(2).entries
+ HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
end
it "should be possible to identify sub items using an html selector (using ids)" do
- HTML::Selector.new('#invoices #subnav1').select(render(:invoices, true)).should have(1).entries
+ HTML::Selector.new('#invoices #subnav1').select(render(:invoices)).should have(1).entries
end
- context 'render_all_levels = false' do
- before(:each) do
- SimpleNavigation.config.render_all_levels = false
- end
+ context 'expand_all => false' do
it "should not render the invoices submenu if the user-primary is active" do
- HTML::Selector.new('#invoices #subnav1').select(render(:users, true)).should be_empty
- HTML::Selector.new('#invoices #subnav2').select(render(:users, true)).should be_empty
+ HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => false)).should be_empty
+ HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
end
end
- context 'render_all_levels = true' do
- before(:each) do
- SimpleNavigation.config.render_all_levels = true
- end
+ context 'expand_all => true' do
it "should render the invoices submenu even if the user-primary is active" do
- HTML::Selector.new('#invoices #subnav1').select(render(:users, true)).should have(1).entry
- HTML::Selector.new('#invoices #subnav2').select(render(:users, true)).should have(1).entry
+ HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
+ HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
end
end
-
+
end
end