pass Grit::Commit to Gollum::Page instances from Gollum::Wiki#pages

This commit is contained in:
rick
2010-07-23 17:39:33 -07:00
parent 5ce149715f
commit 00227a118b
2 changed files with 16 additions and 4 deletions
+11 -4
View File
@@ -171,7 +171,11 @@ module Gollum
# Returns an Array of Gollum::Page instances. # Returns an Array of Gollum::Page instances.
def pages(treeish = nil) def pages(treeish = nil)
treeish ||= 'master' treeish ||= 'master'
tree_list(@repo.commit(treeish).tree) if commit = @repo.commit(treeish)
tree_list(commit)
else
[]
end
end end
# Public: All of the versions that have touched the Page. # Public: All of the versions that have touched the Page.
@@ -212,21 +216,24 @@ module Gollum
# Fill an array with a list of pages. # Fill an array with a list of pages.
# #
# commit - The Grit::Commit
# tree - The Grit::Tree to start with. # tree - The Grit::Tree to start with.
# sub_tree - Optional String specifying the parent path of the Page. # sub_tree - Optional String specifying the parent path of the Page.
# #
# Returns a flat Array of Gollum::Page instances. # Returns a flat Array of Gollum::Page instances.
def tree_list(tree, sub_tree = nil) def tree_list(commit, tree = commit.tree, sub_tree = nil)
list = [] list = []
path = tree.name ? "#{sub_tree}/#{tree.name}" : '' path = tree.name ? "#{sub_tree}/#{tree.name}" : ''
tree.contents.each do |item| tree.contents.each do |item|
case item case item
when Grit::Blob when Grit::Blob
if @page_class.valid_page_name?(item.name) if @page_class.valid_page_name?(item.name)
list << @page_class.new(self).populate(item, path) page = @page_class.new(self).populate(item, path)
page.version = commit
list << page
end end
when Grit::Tree when Grit::Tree
list.push *tree_list(item, path) list.push *tree_list(commit, item, path)
end end
end end
list list
+5
View File
@@ -16,6 +16,11 @@ context "Markup" do
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git])) FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
end end
test "formats page from Wiki#pages" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit)
assert @wiki.pages[0].formatted_data
end
test "double page links no space" do test "double page links no space" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit) @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit)