diff --git a/lib/gollum/frontend/public/css/screen.css b/lib/gollum/frontend/public/css/screen.css index 673c5692..304d1c38 100644 --- a/lib/gollum/frontend/public/css/screen.css +++ b/lib/gollum/frontend/public/css/screen.css @@ -339,6 +339,11 @@ html {overflow-y: scroll;} /* Special markup considerations */ +.wikistyle.gollum.footer { + border-top: 4px solid #f0f0f0; + margin-top: 2em; +} + .wikistyle.gollum > h1:first-child { display: none; } diff --git a/lib/gollum/frontend/templates/page.mustache b/lib/gollum/frontend/templates/page.mustache index 89164917..321814dc 100644 --- a/lib/gollum/frontend/templates/page.mustache +++ b/lib/gollum/frontend/templates/page.mustache @@ -4,9 +4,14 @@ Home | Edit

{{human_name}}

-
+
{{{content}}}
+ {{#has_footer}} + + {{/has_footer}}
diff --git a/lib/gollum/frontend/views/page.rb b/lib/gollum/frontend/views/page.rb index 88f1297e..d3681288 100644 --- a/lib/gollum/frontend/views/page.rb +++ b/lib/gollum/frontend/views/page.rb @@ -1,7 +1,7 @@ module Precious module Views class Page < Layout - attr_reader :content, :page + attr_reader :content, :page, :footer def human_name @page.title @@ -23,6 +23,21 @@ module Precious @page.version.authored_date.strftime("%Y-%m-%d %H:%M:%S") end + def has_footer + @footer ||= @page.footer + !@footer.nil? + end + + def footer_content + @footer ||= @page.footer + @footer.formatted_data + end + + def footer_format + @footer ||= @page.footer + @footer.format.to_s + end + def versions i = @page.versions.size + 1 @page.versions.map do |v| diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 7edb9002..cf28da60 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -148,6 +148,28 @@ module Gollum @wiki.repo.log('master', @path, log_pagination_options(options)) end + # Public: The footer Page. + # + # Returns the footer Page or nil if none exists. + def footer + dirs = self.path.split('/') + dirs.pop + while !dirs.empty? + tree = self.version.tree / dirs.join('/') + if page = find_page_in_this_tree(tree, dirs.join('/'), '_Footer') + return page + end + dirs.pop + end + + tree = self.version.tree + if page = find_page_in_this_tree(tree, '', '_Footer') + return page + end + + return nil + end + ######################################################################### # # Class Methods @@ -245,6 +267,28 @@ module Gollum return nil # nothing was found end + # Find a page in a given tree without recursing into subtrees. + # + # tree - The Grit::Tree in which to look. + # dir - The String path of the given Grit::Tree. + # name - The canonical String page name. + # + # Returns a Gollum::Page or nil if the page could not be found. + def find_page_in_this_tree(tree, dir, name) + treemap = {} + tree.contents.each do |item| + case item + when Grit::Blob + if page_match(name, item.name) + path = dir == '' ? '' : ::File.join('/', dir) + return populate(item, path) + end + end + end + + return nil # nothing was found + end + # Populate the Page with information from the Blob. # # blob - The Grit::Blob that contains the info. diff --git a/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 b/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 new file mode 100644 index 00000000..268d2283 Binary files /dev/null and b/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 differ diff --git a/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef b/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef new file mode 100644 index 00000000..264ea1d5 --- /dev/null +++ b/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef @@ -0,0 +1,3 @@ +xŽAj1 E³ö)t ’ÆÛBs€@…®=# MÀ£â¸÷¯Ïíã¿ÏÛ¬ÖGžó©7UÀ…fò =Q$Ü2—Ä»²Æ%ϼEÜue î·4=:dx–XÔ§¢k 1`Î"Ä™Ï(iôÄ•¿þc ¾¬ÂgÓW·cúÖvhƒK·úQíiuµófõ +Ä )-‰LÝ £²ñ{¾»‰ÀÝšŒ‚ÝlÝ? +MK \ No newline at end of file diff --git a/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 b/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 new file mode 100644 index 00000000..4af136c5 Binary files /dev/null and b/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 differ diff --git a/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 b/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 new file mode 100644 index 00000000..e5f20cad Binary files /dev/null and b/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 differ diff --git a/test/examples/lotr.git/refs/heads/master b/test/examples/lotr.git/refs/heads/master index 29a2baa7..bc3dd288 100644 --- a/test/examples/lotr.git/refs/heads/master +++ b/test/examples/lotr.git/refs/heads/master @@ -1 +1 @@ -94523d7ae48aeba575099dd12926420d8fd0425d +0ed8cbe0a25235bd867e65193c7d837c66b328ef diff --git a/test/test_page.rb b/test/test_page.rb index 31c873a8..4bd2ddcd 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -80,4 +80,16 @@ context "Page" do page = @wiki.page('Eye Of Sauron') assert_equal "Eye Of Sauron", page.title end + + test "top level footer" do + footer = @wiki.page('Home').footer + assert_equal 'Lord of the Rings wiki', footer.raw_data + assert_equal '_Footer.md', footer.path + end + + test "nested footer" do + footer = @wiki.page('Eye Of Sauron').footer + assert_equal "Ones does not simply **walk** into Mordor!\n", footer.raw_data + assert_equal "Mordor/_Footer.md", footer.path + end end \ No newline at end of file