Make pages inherit their sidebar/header/footer from parent directories regardless of the current 'page_file_dir' of the wiki. refs #413 (https://github.com/github/gollum/issues/413)

This commit is contained in:
Darren Oakley
2012-07-09 12:10:41 +01:00
parent 19325930a2
commit 50e494e8e9
4 changed files with 48 additions and 9 deletions
+4 -5
View File
@@ -126,7 +126,7 @@ module Precious
redirect "/#{page.escaped_url_path}"
end
get '/create/*' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = params[:splat].first
@@ -136,7 +136,7 @@ module Precious
mustache :create
end
end
post '/create' do
name = params[:page]
path = sanitize_empty_params(params[:path])
@@ -294,9 +294,8 @@ module Precious
def show_page_or_file(fullpath)
path = extract_path(fullpath)
name = extract_name(fullpath)
# This breaks headers, footers, and sidebars.
# wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
if page = wiki.page(name)
@page = page
+4 -2
View File
@@ -434,7 +434,9 @@ module Gollum
end
# Loads a sub page. Sub page names (footers, headers, sidebars) are prefixed with
# an underscore to distinguish them from other Pages.
# an underscore to distinguish them from other Pages. If there is not one within
# the current directory, starts walking up the directory tree to try and find one
# within parent directories.
#
# name - String page name.
#
@@ -447,7 +449,7 @@ module Gollum
dirs = self.path.split('/')
dirs.pop
map = @wiki.tree_map_for(@wiki.ref)
map = @wiki.tree_map_for(@wiki.ref, true)
while !dirs.empty?
if page = find_page_in_tree(map, name, dirs.join('/'))
page.parent_page = self
+7 -2
View File
@@ -682,10 +682,15 @@ module Gollum
# listing is cached based on its actual commit SHA.
#
# ref - A String ref that is either a commit SHA or references one.
# ignore_page_file_dir - Boolean, if true, searches all files within the git repo, regardless of dir/subdir
#
# Returns an Array of BlobEntry instances.
def tree_map_for(ref)
@access.tree(ref)
def tree_map_for(ref, ignore_page_file_dir=false)
if ignore_page_file_dir
GitAccess.new(path, nil, @repo_is_bare).tree(ref)
else
@access.tree(ref)
end
rescue Grit::GitRuby::Repository::NoSuchShaFound
[]
end
+33
View File
@@ -195,3 +195,36 @@ context "Page" do
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
end
end
context "within a sub-directory" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })
end
test "get existing page" do
page = @wiki.page('Elrond')
assert_equal Gollum::Page, page.class
assert page.raw_data =~ /^# Elrond\n\nElrond/
assert_equal 'Rivendell/Elrond.md', page.path
assert_equal :markdown, page.format
assert_equal @wiki.repo.commits.first.id, page.version.id
end
test "should not get page from parent dir" do
page = @wiki.page('Bilbo Baggins')
assert_equal nil, page
end
test "should inherit header/footer/sidebar pages from parent directories" do
page = @wiki.page('Elrond')
assert_equal Gollum::Page, page.sidebar.class
assert_equal Gollum::Page, page.header.class
assert_equal Gollum::Page, page.footer.class
assert page.sidebar.raw_data =~ /^Lord of the Rings/
assert page.header.raw_data =~ /^Hobbits/
assert page.footer.raw_data =~ /^Lord of the Rings/
end
end