implement File finding
This commit is contained in:
+24
-1
@@ -1,6 +1,6 @@
|
|||||||
module Gollum
|
module Gollum
|
||||||
class File
|
class File
|
||||||
attr_accessor :wiki
|
attr_accessor :wiki, :blob
|
||||||
|
|
||||||
# Initialize a file.
|
# Initialize a file.
|
||||||
#
|
#
|
||||||
@@ -10,5 +10,28 @@ module Gollum
|
|||||||
def initialize(wiki)
|
def initialize(wiki)
|
||||||
self.wiki = wiki
|
self.wiki = wiki
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
+3
-2
@@ -25,10 +25,11 @@ module Gollum
|
|||||||
# Get the static file for a given name.
|
# 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.
|
# Returns a Gollum::File or nil if no matching file was found.
|
||||||
def file(name)
|
def file(name, version = 'master')
|
||||||
File.new(self).find(name)
|
File.new(self).find(name, version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
fbabba862dfa7ac35b39042dd4ad780c9f67b8cb
|
f01428b3138994aab19d5f880b6f37336ddf1f24
|
||||||
|
|||||||
@@ -7,5 +7,11 @@ context "File" do
|
|||||||
|
|
||||||
test "new file" do
|
test "new file" do
|
||||||
file = Gollum::File.new(@wiki)
|
file = Gollum::File.new(@wiki)
|
||||||
|
assert_nil file.raw_data
|
||||||
|
end
|
||||||
|
|
||||||
|
test "existing file" do
|
||||||
|
file = @wiki.file("Mordor/todo.txt")
|
||||||
|
assert_equal "[ ] Write section on Ents\n", file.raw_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
+1
-1
@@ -18,7 +18,7 @@ context "Page" do
|
|||||||
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 'Bilbo-Baggins.md', page.path
|
||||||
assert_equal :markdown, page.format
|
assert_equal :markdown, page.format
|
||||||
assert_equal 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb', page.version.id
|
assert_equal @wiki.repo.commits.first.id, page.version.id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get nested page" do
|
test "get nested page" do
|
||||||
|
|||||||
Reference in New Issue
Block a user