Wiki#pages uses the treemap
This commit is contained in:
@@ -22,11 +22,27 @@ module Gollum
|
|||||||
@name ||= ::File.basename(@path)
|
@name ||= ::File.basename(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Gets the Grit::Blob instance for this blob.
|
# Gets a Grit::Blob instance for this blob.
|
||||||
|
#
|
||||||
|
# repo - Grit::Repo instance for the Grit::Blob.
|
||||||
|
#
|
||||||
|
# Returns an unbaked Grit::Blob instance.
|
||||||
def blob(repo)
|
def blob(repo)
|
||||||
@blob ||= Grit::Blob.create(repo, :id => @sha, :name => @name)
|
@blob ||= Grit::Blob.create(repo, :id => @sha, :name => @name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets a Page instance for this blob.
|
||||||
|
#
|
||||||
|
# wiki - Gollum::Wiki instance for the Gollum::Page
|
||||||
|
#
|
||||||
|
# Returns a Gollum::Page instance.
|
||||||
|
def page(wiki, commit)
|
||||||
|
blob = self.blob(wiki.repo)
|
||||||
|
page = wiki.page_class.new(wiki).populate(blob, self.dir)
|
||||||
|
page.version = commit
|
||||||
|
page
|
||||||
|
end
|
||||||
|
|
||||||
# Normalizes a given directory name for searching through tree paths.
|
# Normalizes a given directory name for searching through tree paths.
|
||||||
# Ensures that a directory begins with a slash, or
|
# Ensures that a directory begins with a slash, or
|
||||||
#
|
#
|
||||||
|
|||||||
+1
-1
@@ -271,7 +271,7 @@ module Gollum
|
|||||||
map.each do |entry|
|
map.each do |entry|
|
||||||
next unless checked_dir.nil? || entry.dir.downcase == checked_dir
|
next unless checked_dir.nil? || entry.dir.downcase == checked_dir
|
||||||
next unless page_match(name, entry.name)
|
next unless page_match(name, entry.name)
|
||||||
return self.class.new(@wiki).populate(entry.blob(@wiki.repo), entry.dir)
|
return entry.page(@wiki, @version)
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil # nothing was found
|
return nil # nothing was found
|
||||||
|
|||||||
+13
-24
@@ -207,12 +207,7 @@ 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'
|
tree_list(treeish || 'master')
|
||||||
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.
|
||||||
@@ -256,6 +251,12 @@ module Gollum
|
|||||||
# Returns the Hash cache.
|
# Returns the Hash cache.
|
||||||
attr_reader :tree_map
|
attr_reader :tree_map
|
||||||
|
|
||||||
|
# Gets the page class used by all instances of this Wiki.
|
||||||
|
attr_reader :page_class
|
||||||
|
|
||||||
|
# Gets the file class used by all instances of this Wiki.
|
||||||
|
attr_reader :file_class
|
||||||
|
|
||||||
# Normalize the data.
|
# Normalize the data.
|
||||||
#
|
#
|
||||||
# data - The String data to be normalized.
|
# data - The String data to be normalized.
|
||||||
@@ -267,27 +268,15 @@ module Gollum
|
|||||||
|
|
||||||
# Fill an array with a list of pages.
|
# Fill an array with a list of pages.
|
||||||
#
|
#
|
||||||
# commit - The Grit::Commit
|
# ref - A String ref that is either a commit SHA or references one.
|
||||||
# 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.
|
# Returns a flat Array of Gollum::Page instances.
|
||||||
def tree_list(commit, tree = commit.tree, sub_tree = nil)
|
def tree_list(ref)
|
||||||
list = []
|
tree_map_for(ref).inject([]) do |list, entry|
|
||||||
path = tree.name ? "#{sub_tree}/#{tree.name}" : ''
|
next list unless @page_class.valid_page_name?(entry.name)
|
||||||
tree.contents.each do |item|
|
sha = ref_map[ref]
|
||||||
case item
|
list << entry.page(self, @repo.commit(sha))
|
||||||
when Grit::Blob
|
|
||||||
if @page_class.valid_page_name?(item.name)
|
|
||||||
page = @page_class.new(self).populate(item, path)
|
|
||||||
page.version = commit
|
|
||||||
list << page
|
|
||||||
end
|
end
|
||||||
when Grit::Tree
|
|
||||||
list.push *tree_list(commit, item, path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Determine if a given page path is scheduled to be deleted in the next
|
# Determine if a given page path is scheduled to be deleted in the next
|
||||||
|
|||||||
Reference in New Issue
Block a user