compute directory path of pages
This commit is contained in:
+25
-4
@@ -2,7 +2,7 @@ module Gollum
|
|||||||
class Page
|
class Page
|
||||||
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
||||||
|
|
||||||
attr_accessor :wiki, :blob, :version
|
attr_accessor :wiki, :blob, :path, :version
|
||||||
|
|
||||||
# Initialize a page.
|
# Initialize a page.
|
||||||
#
|
#
|
||||||
@@ -16,10 +16,12 @@ module Gollum
|
|||||||
# Populate this Page with information from the Blob.
|
# Populate this Page with information from the Blob.
|
||||||
#
|
#
|
||||||
# blob - The Grit::Blob that contains the info.
|
# blob - The Grit::Blob that contains the info.
|
||||||
|
# path - The String directory path of the page file.
|
||||||
#
|
#
|
||||||
# Returns the populated Gollum::Page.
|
# Returns the populated Gollum::Page.
|
||||||
def populate(blob)
|
def populate(blob, path)
|
||||||
self.blob = blob
|
self.blob = blob
|
||||||
|
self.path = (path + '/' + blob.name)[1..-1]
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,14 +98,19 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns a Gollum::Page or nil if the page could not be found.
|
# Returns a Gollum::Page or nil if the page could not be found.
|
||||||
def find_page_in_tree(tree, name)
|
def find_page_in_tree(tree, name)
|
||||||
|
treemap = {}
|
||||||
trees = [tree]
|
trees = [tree]
|
||||||
|
|
||||||
while !trees.empty?
|
while !trees.empty?
|
||||||
trees.shift.contents.each do |item|
|
ptree = trees.shift
|
||||||
|
ptree.contents.each do |item|
|
||||||
case item
|
case item
|
||||||
when Grit::Blob
|
when Grit::Blob
|
||||||
return populate(item) if page_match(name, item.name)
|
if page_match(name, item.name)
|
||||||
|
return populate(item, tree_path(treemap, ptree))
|
||||||
|
end
|
||||||
when Grit::Tree
|
when Grit::Tree
|
||||||
|
treemap[item] = ptree
|
||||||
trees << item
|
trees << item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -112,6 +119,20 @@ module Gollum
|
|||||||
return nil # nothing was found
|
return nil # nothing was found
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The full directory path for the given tree.
|
||||||
|
#
|
||||||
|
# treemap - The Hash treemap containing parentage information.
|
||||||
|
# tree - The Grit::Tree for which to compute the path.
|
||||||
|
#
|
||||||
|
# Returns the String path.
|
||||||
|
def tree_path(treemap, tree)
|
||||||
|
if ptree = treemap[tree]
|
||||||
|
tree_path(treemap, ptree) + '/' + tree.name
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Compare the canonicalized versions of the two names.
|
# Compare the canonicalized versions of the two names.
|
||||||
#
|
#
|
||||||
# name - The human or canonical String page name.
|
# name - The human or canonical String page name.
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
module Gollum
|
||||||
|
class Version
|
||||||
|
attr_accessor :commit
|
||||||
|
|
||||||
|
def initialize(commit)
|
||||||
|
self.commit = commit
|
||||||
|
end
|
||||||
|
|
||||||
|
# The SHA1 commit ID.
|
||||||
|
#
|
||||||
|
# The String ID.
|
||||||
|
def id
|
||||||
|
self.commit.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
x�ŽAjB1@»Î)æJ&Ñ™"nÜ\'™‰m!$ÆEo߆nïÁ«Öû÷„°ã�9TA0S+I˜¨*i.A«Ï©qh"Ã>bLâžyè2AZ %TöŒH-¡–Jå÷ZI�˜
|
||||||
|
ë�êÎå÷ü²7ëpúš¶lî:pœÖÏÝ~¬ÛVë'ÀÀè}ÂaãÉ{·Òõr®òÿz—Eà™
|
||||||
|
m}¸ü*XƒÏü¶¸?øçOi
|
||||||
@@ -1 +1 @@
|
|||||||
df26e61e707116f81ebc6b935ec6d1676b7e96c4
|
fbabba862dfa7ac35b39042dd4ad780c9f67b8cb
|
||||||
|
|||||||
+7
-1
@@ -16,8 +16,14 @@ context "Page" do
|
|||||||
assert_equal Gollum::Page, page.class
|
assert_equal Gollum::Page, page.class
|
||||||
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||||
assert page.formatted_data =~ /<h1>Bilbo Baggins<\/h1>\n\n<p>Bilbo Baggins/
|
assert page.formatted_data =~ /<h1>Bilbo Baggins<\/h1>\n\n<p>Bilbo Baggins/
|
||||||
|
assert_equal 'Bilbo-Baggins.md', page.path
|
||||||
assert_equal :markdown, page.format
|
assert_equal :markdown, page.format
|
||||||
assert_equal 'df26e61e707116f81ebc6b935ec6d1676b7e96c4', page.version.id
|
assert_equal 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb', page.version.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "get nested page" do
|
||||||
|
page = @wiki.page('Eye Of Sauron')
|
||||||
|
assert_equal 'Mordor/Eye-Of-Sauron.md', page.path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "no page match" do
|
test "no page match" do
|
||||||
|
|||||||
Reference in New Issue
Block a user