Wiki#pages only returns pages
This commit is contained in:
+23
-2
@@ -15,6 +15,27 @@ module Gollum
|
|||||||
:pod => "Pod",
|
:pod => "Pod",
|
||||||
:roff => "roff" }
|
:roff => "roff" }
|
||||||
|
|
||||||
|
# Checks if a filename has a valid extension understood by GitHub::Markup.
|
||||||
|
#
|
||||||
|
# filename - String filename, like "Home.md".
|
||||||
|
#
|
||||||
|
# Returns the matching String basename of the file without the extension.
|
||||||
|
def self.valid_filename?(filename)
|
||||||
|
filename && filename.to_s =~ VALID_PAGE_RE && $1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Checks if a filename has a valid extension understood by GitHub::Markup.
|
||||||
|
# Also, checks if the filename has no "_" in the front (such as
|
||||||
|
# _Footer.md).
|
||||||
|
#
|
||||||
|
# filename - String filename, like "Home.md".
|
||||||
|
#
|
||||||
|
# Returns the matching String basename of the file without the extension.
|
||||||
|
def self.valid_page_name?(filename)
|
||||||
|
match = valid_filename?(filename)
|
||||||
|
filename =~ /^_/ ? false : match
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Initialize a page.
|
# Public: Initialize a page.
|
||||||
#
|
#
|
||||||
# wiki - The Gollum::Wiki in question.
|
# wiki - The Gollum::Wiki in question.
|
||||||
@@ -228,8 +249,8 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns a Boolean.
|
# Returns a Boolean.
|
||||||
def page_match(name, filename)
|
def page_match(name, filename)
|
||||||
if filename =~ VALID_PAGE_RE
|
if match = self.class.valid_filename?(filename)
|
||||||
Page.cname(name) == Page.cname($1)
|
Page.cname(name) == Page.cname(match)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
+3
-1
@@ -222,7 +222,9 @@ module Gollum
|
|||||||
tree.contents.each do |item|
|
tree.contents.each do |item|
|
||||||
case item
|
case item
|
||||||
when Grit::Blob
|
when Grit::Blob
|
||||||
list << @page_class.new(self).populate(item, path)
|
if @page_class.valid_page_name?(item.name)
|
||||||
|
list << @page_class.new(self).populate(item, path)
|
||||||
|
end
|
||||||
when Grit::Tree
|
when Grit::Tree
|
||||||
list.push *tree_list(item, path)
|
list.push *tree_list(item, path)
|
||||||
end
|
end
|
||||||
|
|||||||
+7
-17
@@ -40,6 +40,13 @@ context "Wiki" do
|
|||||||
f01428b3138994aab19d5f880b6f37336ddf1f24),
|
f01428b3138994aab19d5f880b6f37336ddf1f24),
|
||||||
@wiki.log(:page => 2).map { |c| c.id }
|
@wiki.log(:page => 2).map { |c| c.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "list pages" do
|
||||||
|
pages = @wiki.pages
|
||||||
|
assert_equal \
|
||||||
|
%w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile),
|
||||||
|
pages.map { |p| p.name }.sort
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Wiki page writing" do
|
context "Wiki page writing" do
|
||||||
@@ -151,23 +158,6 @@ 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