diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 4e0cf4f9..c0368caf 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -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 diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index f93dc19d..3ec3305d 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -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 diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 089b25d5..11c156c8 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -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 diff --git a/test/test_page.rb b/test/test_page.rb index b10d4c1d..fb41a792 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -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 +