I can't believe I missed the include_page? method.
Now supports exactly the same standards as the top level list elements, such as unpublished and excluded urls
This commit is contained in:
parent
825521a5d4
commit
7d529f22d7
@ -54,6 +54,7 @@ module Locomotive
|
||||
|
||||
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 = %{<ul id="#{@options[:id]}-#{page.slug.dasherize}">}
|
||||
children.each do |c, page|
|
||||
@ -111,6 +104,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
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ 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 => '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)
|
||||
@ -59,6 +60,26 @@ 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 /<li id="child-2" class="link last">/
|
||||
output.should match /<li id="sub-child-1" class="link first last">/
|
||||
output.should_not match /sub-child-2/
|
||||
|
||||
output = render_nav('site', {}, 'depth: 2, exclude: "child_2"')
|
||||
|
||||
output.should match /<li id="child-1" class="link first last">/
|
||||
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 /<li id="child-1" class="link first"><a href="\/child_1"><span><\/span>Child #1<\/a>/
|
||||
render_nav('site', {}, 'icon: before').should match /<li id="child-1" class="link first"><a href="\/child_1"><span><\/span>Child #1<\/a>/
|
||||
|
Loading…
Reference in New Issue
Block a user