implement File finding
This commit is contained in:
+24
-1
@@ -1,6 +1,6 @@
|
||||
module Gollum
|
||||
class File
|
||||
attr_accessor :wiki
|
||||
attr_accessor :wiki, :blob
|
||||
|
||||
# Initialize a file.
|
||||
#
|
||||
@@ -10,5 +10,28 @@ module Gollum
|
||||
def initialize(wiki)
|
||||
self.wiki = wiki
|
||||
end
|
||||
|
||||
# The raw contents of the page.
|
||||
#
|
||||
# Returns the String data.
|
||||
def raw_data
|
||||
self.blob.data rescue nil
|
||||
end
|
||||
|
||||
# Find a file in the given Gollum repo.
|
||||
#
|
||||
# name - The full String path.
|
||||
# version - The String version ID to find.
|
||||
#
|
||||
# Returns a Gollum::File or nil if the file could not be found.
|
||||
def find(name, version)
|
||||
commit = self.wiki.repo.commit(version)
|
||||
if blob = commit.tree / name
|
||||
self.blob = blob
|
||||
self
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
+4
-3
@@ -24,11 +24,12 @@ module Gollum
|
||||
|
||||
# Get the static file for a given name.
|
||||
#
|
||||
# name - The full String pathname to the file.
|
||||
# name - The full String pathname to the file.
|
||||
# version - The String version ID to find (default: "master").
|
||||
#
|
||||
# Returns a Gollum::File or nil if no matching file was found.
|
||||
def file(name)
|
||||
File.new(self).find(name)
|
||||
def file(name, version = 'master')
|
||||
File.new(self).find(name, version)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user