Add Wiki#files for list of non-page files.

This commit is contained in:
trans
2012-06-22 08:23:46 -04:00
parent 8fd11e8fdb
commit 754485c306
4 changed files with 62 additions and 3 deletions
+13 -1
View File
@@ -48,6 +48,18 @@ module Gollum
page
end
# Gets a File instance for this blob.
#
# wiki - Gollum::Wiki instance for the Gollum::File
#
# Returns a Gollum::File instance.
def file(wiki, commit)
blob = self.blob(wiki.repo)
file = wiki.file_class.new(wiki).populate(blob, self.dir)
file.version = commit
file
end
def inspect
%(#<Gollum::BlobEntry #{@sha} #{@path}>)
end
@@ -75,4 +87,4 @@ module Gollum
dir
end
end
end
end
+15 -2
View File
@@ -19,6 +19,7 @@ module Gollum
def name
@blob && @blob.name
end
alias filename name
# Public: The raw contents of the page.
#
@@ -28,7 +29,7 @@ module Gollum
end
# Public: The Grit::Commit version of the file.
attr_reader :version
attr_accessor :version
# Public: The String path of the file.
attr_reader :path
@@ -38,6 +39,18 @@ module Gollum
@blob.mime_type
end
# Populate the Page with information from the Blob.
#
# blob - The Grit::Blob that contains the info.
# path - The String directory path of the page file.
#
# Returns the populated Gollum::Page.
def populate(blob, path=nil)
@blob = blob
@path = "#{path}/#{blob.name}"[1..-1]
self
end
#########################################################################
#
# Internal Methods
@@ -61,4 +74,4 @@ module Gollum
end
end
end
end
end
+27
View File
@@ -446,6 +446,15 @@ module Gollum
tree_list(treeish || @ref)
end
# Public: Lists all non-page files for this wiki.
#
# treeish - The String commit ID or ref to find (default: @ref)
#
# Returns an Array of Gollum::File instances.
def files(treeish = nil)
file_list(treeish || @ref)
end
# Public: Returns the number of pages accessible from a commit
#
# ref - A String ref that is either a commit SHA or references one.
@@ -595,6 +604,24 @@ module Gollum
end
end
# Fill an array with a list of files.
#
# ref - A String ref that is either a commit SHA or references one.
#
# Returns a flat Array of Gollum::File instances.
def file_list(ref)
if sha = @access.ref_to_sha(ref)
commit = @access.commit(sha)
tree_map_for(sha).inject([]) do |list, entry|
next list if entry.name.start_with?('_')
next list if @page_class.valid_page_name?(entry.name)
list << entry.file(self, commit)
end
else
[]
end
end
# Creates a reverse diff for the given SHAs on the given Gollum::Page.
#
# page - The Gollum::Page to scope the patch to, or a String Path.
+7
View File
@@ -58,6 +58,13 @@ context "Wiki" do
pages.map { |p| p.filename }.sort
end
test "list files" do
files = @wiki.files
assert_equal \
['Data.csv', 'eye.jpg', 'todo.txt'],
files.map { |p| p.filename }.sort
end
test "counts pages" do
assert_equal 6, @wiki.size
end