Fix breadcrumbs (#1387)
This commit is contained in:
@@ -26,14 +26,14 @@ module Precious
|
||||
end
|
||||
|
||||
def breadcrumb
|
||||
path = Pathname.new(@page.url_path_title)
|
||||
path = Pathname.new(@page.url_path).parent
|
||||
return '' if path.to_s == '.'
|
||||
breadcrumb = []
|
||||
path.descend do |crumb|
|
||||
element = "#{crumb.basename}"
|
||||
next if element == @page.title
|
||||
breadcrumb << %{<a href="#{pages_path}/#{crumb}/">#{element}</a>}
|
||||
end
|
||||
breadcrumb.empty? ? "" : breadcrumb.join(" / ") << " /"
|
||||
breadcrumb.join(' / ') << ' /'
|
||||
end
|
||||
|
||||
def content
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/views/page', __FILE__
|
||||
|
||||
|
||||
context "Precious::Views::Page" do
|
||||
setup do
|
||||
examples = testpath "examples"
|
||||
@@ -108,4 +109,23 @@ EOS
|
||||
actual = @view.title
|
||||
assert_equal title, actual
|
||||
end
|
||||
|
||||
test "breadcrumbs" do
|
||||
@wiki.write_page('subdir/BC Test 1', :markdown, 'Test', commit_details)
|
||||
page = @wiki.page('subdir/BC Test 1')
|
||||
|
||||
@view = Precious::Views::Page.new
|
||||
@view.instance_variable_set :@page, page
|
||||
@view.instance_variable_set :@content, page.formatted_data
|
||||
assert_equal @view.breadcrumb, '<a href="/gollum/pages/subdir/">subdir</a> /'
|
||||
|
||||
# No breadcrumb on unnested page
|
||||
@wiki.write_page('BC Test 2', :markdown, 'Test', commit_details)
|
||||
page = @wiki.page('BC Test 2')
|
||||
|
||||
@view = Precious::Views::Page.new
|
||||
@view.instance_variable_set :@page, page
|
||||
@view.instance_variable_set :@content, page.formatted_data
|
||||
assert_equal @view.breadcrumb, ''
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user