diff --git a/lib/locomotive/liquid/tags/nav.rb b/lib/locomotive/liquid/tags/nav.rb
index 4a31d7ec..7c653af5 100644
--- a/lib/locomotive/liquid/tags/nav.rb
+++ b/lib/locomotive/liquid/tags/nav.rb
@@ -53,7 +53,8 @@ module Locomotive
end
private
-
+
+ # Determines root node for the list
def fetch_entries(context)
@current_page = context.registers[:page]
@@ -68,16 +69,7 @@ module Locomotive
children.delete_if { |p| !include_page?(p) }
end
- def include_page?(page)
- if page.templatized? || !page.published?
- false
- elsif @options[:exclude]
- (page.fullpath =~ @options[:exclude]).nil?
- else
- true
- end
- end
-
+ # Returns a list element, a link to the page and its children
def render_entry_link(page,css,depth)
selected = @current_page.fullpath =~ /^#{page.fullpath}/ ? ' on' : ''
@@ -92,10 +84,11 @@ module Locomotive
output.strip
end
+ # Recursively creates a nested unordered list for the depth specified
def render_entry_children(page,depth)
output = %{}
- children = page.children_with_minimal_attributes.reject { |c| c.templatized? }
+ children = page.children_with_minimal_attributes.reject { |c| !include_page?(c) }
if children.present?
output = %{
}
children.each do |c, page|
@@ -110,6 +103,17 @@ module Locomotive
output
end
+
+ # Determines whether or not a page should be a part of the menu
+ def include_page?(page)
+ if page.templatized? || !page.published?
+ false
+ elsif @options[:exclude]
+ (page.fullpath =~ @options[:exclude]).nil?
+ else
+ true
+ end
+ end
::Liquid::Template.register_tag('nav', Nav)
end
diff --git a/spec/lib/locomotive/liquid/tags/nav_spec.rb b/spec/lib/locomotive/liquid/tags/nav_spec.rb
index 4474640d..15072109 100644
--- a/spec/lib/locomotive/liquid/tags/nav_spec.rb
+++ b/spec/lib/locomotive/liquid/tags/nav_spec.rb
@@ -14,7 +14,8 @@ describe Locomotive::Liquid::Tags::Nav do
other_children = [
Page.new(:title => 'Child #2.1', :fullpath => 'child_2/sub_child_1', :slug => 'sub_child_1', :published => true),
Page.new(:title => 'Child #2.2', :fullpath => 'child_2/sub_child_2', :slug => 'sub_child_2', :published => true),
- Page.new(:title => 'Templatized #2.3', :fullpath => 'child_2/sub_child_template_3', :slug => 'sub_child_template_3', :published => true, :templatized => true)
+ Page.new(:title => 'Unpublished #2.2', :fullpath => 'child_2/sub_child_unpublishd_2', :slug => 'sub_child_unpublished_2', :published => false),
+ Page.new(:title => 'Templatized #2.3', :fullpath => 'child_2/sub_child_template_3', :slug => 'sub_child_template_3', :published => true, :templatized => true)
]
@home.children.last.stubs(:children_with_minimal_attributes).returns(other_children)
@home.children.last.stubs(:children).returns(other_children)
@@ -58,7 +59,27 @@ describe Locomotive::Liquid::Tags::Nav do
output.should_not match /sub-child-template-3/
end
-
+
+ it 'does not render unpublished pages' do
+ output = render_nav('site', {}, 'depth: 2')
+
+ output.should_not match /sub-child-unpublished-3/
+ end
+
+ it 'does not render nested excluded pages' do
+ output = render_nav('site', {}, 'depth: 2, exclude: "child_2/sub_child_2"')
+
+ output.should match /- /
+ output.should match /
- /
+ output.should_not match /sub-child-2/
+
+ output = render_nav('site', {}, 'depth: 2, exclude: "child_2"')
+
+ output.should match /
- /
+ output.should_not match /child-2/
+ output.should_not match /sub-child/
+ end
+
it 'adds an icon before the link' do
render_nav('site', {}, 'icon: true').should match /
- <\/span>Child #1<\/a>/
render_nav('site', {}, 'icon: before').should match /
- <\/span>Child #1<\/a>/