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
@ -53,7 +53,8 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Determines root node for the list
|
||||||
def fetch_entries(context)
|
def fetch_entries(context)
|
||||||
@current_page = context.registers[:page]
|
@current_page = context.registers[:page]
|
||||||
|
|
||||||
@ -68,16 +69,7 @@ module Locomotive
|
|||||||
children.delete_if { |p| !include_page?(p) }
|
children.delete_if { |p| !include_page?(p) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_page?(page)
|
# Returns a list element, a link to the page and its children
|
||||||
if page.templatized? || !page.published?
|
|
||||||
false
|
|
||||||
elsif @options[:exclude]
|
|
||||||
(page.fullpath =~ @options[:exclude]).nil?
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_entry_link(page,css,depth)
|
def render_entry_link(page,css,depth)
|
||||||
selected = @current_page.fullpath =~ /^#{page.fullpath}/ ? ' on' : ''
|
selected = @current_page.fullpath =~ /^#{page.fullpath}/ ? ' on' : ''
|
||||||
|
|
||||||
@ -92,10 +84,11 @@ module Locomotive
|
|||||||
output.strip
|
output.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Recursively creates a nested unordered list for the depth specified
|
||||||
def render_entry_children(page,depth)
|
def render_entry_children(page,depth)
|
||||||
output = %{}
|
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?
|
if children.present?
|
||||||
output = %{<ul id="#{@options[:id]}-#{page.slug.dasherize}">}
|
output = %{<ul id="#{@options[:id]}-#{page.slug.dasherize}">}
|
||||||
children.each do |c, page|
|
children.each do |c, page|
|
||||||
@ -110,6 +103,17 @@ module Locomotive
|
|||||||
|
|
||||||
output
|
output
|
||||||
end
|
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)
|
::Liquid::Template.register_tag('nav', Nav)
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,8 @@ describe Locomotive::Liquid::Tags::Nav do
|
|||||||
other_children = [
|
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.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 => '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_with_minimal_attributes).returns(other_children)
|
||||||
@home.children.last.stubs(:children).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/
|
output.should_not match /sub-child-template-3/
|
||||||
end
|
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
|
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: 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>/
|
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