diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 77b31934..9ef0a143 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -298,9 +298,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..c3967df9 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -682,10 +682,16 @@ 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 && !@page_file_dir.nil? + @root_access ||= GitAccess.new(path, nil, @repo_is_bare) + @root_access.tree(ref) + else + @access.tree(ref) + end rescue Grit::GitRuby::Repository::NoSuchShaFound [] end diff --git a/test/examples/lotr.git/logs/HEAD b/test/examples/lotr.git/logs/HEAD index 6cba614a..31a4e256 100644 --- a/test/examples/lotr.git/logs/HEAD +++ b/test/examples/lotr.git/logs/HEAD @@ -3,3 +3,5 @@ a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell 1309107565 +0200 commit: Test out whitespace with Sam 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 b16b3d9fad9d78e5a669e7f33d94c96da374eccd kristi 1336983525 -0700 push b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5c kristi 1336984025 -0700 push +b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley 1341830099 +0100 push +cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley 1341830833 +0100 push diff --git a/test/examples/lotr.git/logs/refs/heads/master b/test/examples/lotr.git/logs/refs/heads/master index 6cba614a..31a4e256 100644 --- a/test/examples/lotr.git/logs/refs/heads/master +++ b/test/examples/lotr.git/logs/refs/heads/master @@ -3,3 +3,5 @@ a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell 1309107565 +0200 commit: Test out whitespace with Sam 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 b16b3d9fad9d78e5a669e7f33d94c96da374eccd kristi 1336983525 -0700 push b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5c kristi 1336984025 -0700 push +b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley 1341830099 +0100 push +cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley 1341830833 +0100 push diff --git a/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 b/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 new file mode 100644 index 00000000..415ae116 Binary files /dev/null and b/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 differ diff --git a/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 b/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 new file mode 100644 index 00000000..e0fb454f Binary files /dev/null and b/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 differ diff --git a/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 b/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 new file mode 100644 index 00000000..c2229ba7 Binary files /dev/null and b/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 differ diff --git a/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 b/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 new file mode 100644 index 00000000..4b894d58 --- /dev/null +++ b/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 @@ -0,0 +1 @@ +xMJ1F])j0S4(ZTe& 187pP55PNߴ*jzAFDV&cUli8SGIp0KQb>0ХJ'zwL}ǕRއè4p#^?<2k%sec8Q*|vipb;z{bT\ \ No newline at end of file diff --git a/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd b/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd new file mode 100644 index 00000000..92192562 --- /dev/null +++ b/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd @@ -0,0 +1,2 @@ +xN0EY+fjǏHF&jWcvWW::g*P 1΁CY` &"[k<3" ZOгѫ|ѽ.*iy} wtˆko/=[XRt# +}vt(Ŝ]-=)&)]/ \ No newline at end of file diff --git a/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df b/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df new file mode 100644 index 00000000..e931c46b --- /dev/null +++ b/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df @@ -0,0 +1 @@ +xEN@ D+FKR$h:8NbENgTI wW8hɖBT|QK. ylU;dM18ʢ\&fMmA3qXxwLŧ6C8I?dzT͍d Tjf̱ 9]<7[ b#t'Ǭga.BaH\d%ܬ[ŧRv/b \ No newline at end of file diff --git a/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 b/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 new file mode 100644 index 00000000..74cbd3c1 Binary files /dev/null and b/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 differ diff --git a/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 b/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 new file mode 100644 index 00000000..670f5931 Binary files /dev/null and b/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 differ diff --git a/test/examples/lotr.git/refs/heads/master b/test/examples/lotr.git/refs/heads/master index bd1b8af0..a19ee561 100644 --- a/test/examples/lotr.git/refs/heads/master +++ b/test/examples/lotr.git/refs/heads/master @@ -1 +1 @@ -b0de6e794dfdc7ef3400e894225bfe23308aae5c +629aa678272b017a4d136d35e77ac94d80b08dc2 diff --git a/test/test_committer.rb b/test/test_committer.rb index 494b12f5..57d8c2b8 100644 --- a/test/test_committer.rb +++ b/test/test_committer.rb @@ -50,7 +50,7 @@ context "Wiki" do end test "parents with default master ref" do - ref = 'b0de6e794dfdc7ef3400e894225bfe23308aae5c' + ref = '629aa678272b017a4d136d35e77ac94d80b08dc2' committer = Gollum::Committer.new(@wiki) assert_equal ref, committer.parents.first.sha end diff --git a/test/test_git_access.rb b/test/test_git_access.rb index 3cd8d0ac..df49b17d 100644 --- a/test/test_git_access.rb +++ b/test/test_git_access.rb @@ -18,7 +18,7 @@ context "GitAccess" do assert @access.ref_map.empty? assert @access.tree_map.empty? @access.tree 'master' - assert_equal({"master"=>"b0de6e794dfdc7ef3400e894225bfe23308aae5c"}, @access.ref_map) + assert_equal({"master"=>"629aa678272b017a4d136d35e77ac94d80b08dc2"}, @access.ref_map) @access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3' map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'] 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 + diff --git a/test/test_wiki.rb b/test/test_wiki.rb index 63303f67..5fa7c0f6 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -54,7 +54,7 @@ context "Wiki" do test "list pages" do pages = @wiki.pages assert_equal \ - ['Bilbo-Baggins.md', 'Boromir.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'], + ['Bilbo-Baggins.md', 'Boromir.md', 'Elrond.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'], pages.map { |p| p.filename }.sort end @@ -66,7 +66,7 @@ context "Wiki" do end test "counts pages" do - assert_equal 6, @wiki.size + assert_equal 7, @wiki.size end test "text_data" do