add Gollum::Wiki#pages
This commit is contained in:
@@ -111,6 +111,16 @@ module Gollum
|
|||||||
index.commit(commit[:message], [pcommit], actor)
|
index.commit(commit[:message], [pcommit], actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Lists all pages for this wiki.
|
||||||
|
#
|
||||||
|
# treeish - The String commit ID or ref to find (default: master)
|
||||||
|
#
|
||||||
|
# Returns an Array of Gollum::Page instances.
|
||||||
|
def pages(treeish = nil)
|
||||||
|
treeish ||= 'master'
|
||||||
|
tree_list(@repo.commit(treeish).tree)
|
||||||
|
end
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
#
|
#
|
||||||
# Internal Methods
|
# Internal Methods
|
||||||
@@ -127,6 +137,26 @@ module Gollum
|
|||||||
# Returns the String path.
|
# Returns the String path.
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
|
||||||
|
# Fill an array with a list of pages.
|
||||||
|
#
|
||||||
|
# tree - The Grit::Tree to start with.
|
||||||
|
# sub_tree - Optional String specifying the parent path of the Page.
|
||||||
|
#
|
||||||
|
# Returns a flat Array of Gollum::Page instances.
|
||||||
|
def tree_list(tree, sub_tree = nil)
|
||||||
|
list = []
|
||||||
|
path = tree.name ? "#{sub_tree}/#{tree.name}" : ''
|
||||||
|
tree.contents.each do |item|
|
||||||
|
case item
|
||||||
|
when Grit::Blob
|
||||||
|
list << Page.new(self).populate(item, path)
|
||||||
|
when Grit::Tree
|
||||||
|
list.push *tree_list(item, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
list
|
||||||
|
end
|
||||||
|
|
||||||
# Fill an index with the existing state of the repository.
|
# Fill an index with the existing state of the repository.
|
||||||
#
|
#
|
||||||
# tree - The Grit::Tree to start with.
|
# tree - The Grit::Tree to start with.
|
||||||
|
|||||||
@@ -89,6 +89,23 @@ context "Wiki page writing" do
|
|||||||
assert @wiki.page("Gollum")
|
assert @wiki.page("Gollum")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "list pages" do
|
||||||
|
commit = { :message => "Gollum page",
|
||||||
|
:name => "Tom Preston-Werner",
|
||||||
|
:email => "tom@github.com" }
|
||||||
|
|
||||||
|
index = @wiki.repo.index
|
||||||
|
index.add("greek/Bilbo-Baggins.md", "hi")
|
||||||
|
index.add("Gollum.md", "hi")
|
||||||
|
index.commit("Add alpha.jpg")
|
||||||
|
|
||||||
|
pages = @wiki.pages
|
||||||
|
assert_equal "Gollum.md", pages[0].path
|
||||||
|
assert_equal "Gollum.md", pages[0].name
|
||||||
|
assert_equal "greek/Bilbo-Baggins.md", pages[1].path
|
||||||
|
assert_equal "Bilbo-Baggins.md", pages[1].name
|
||||||
|
end
|
||||||
|
|
||||||
teardown do
|
teardown 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
|
||||||
|
|||||||
Reference in New Issue
Block a user