file links

This commit is contained in:
Tom Preston-Werner
2010-04-19 11:24:55 -07:00
parent 342edec448
commit 857c6b5eb8
3 changed files with 52 additions and 14 deletions
+5
View File
@@ -8,6 +8,7 @@ module Gollum
def initialize(wiki)
@wiki = wiki
@blob = nil
@path = nil
end
# Public: The on-disk filename of the file.
@@ -27,6 +28,9 @@ module Gollum
# Public: The Grit::Commit version of the file.
attr_reader :version
# Public: The String path of the file.
attr_reader :path
#########################################################################
#
# Internal Methods
@@ -43,6 +47,7 @@ module Gollum
commit = @wiki.repo.commit(version)
if blob = commit.tree / name
@blob = blob
@path = name
@version = commit
self
else
+25 -14
View File
@@ -77,19 +77,8 @@ module Gollum
parts = tag.split('|')
name = parts[0].strip
if name =~ /^\//
if file = @wiki.file(name[1..-1], @version)
%{<img src="/#{file.name}" />}
else
nil
end
else
path = ::File.join(@dir, name)
if file = @wiki.file(path, @version)
%{<img src="/#{path}" />}
else
nil
end
if file = find_file(name)
%{<img src="/#{file.path}" />}
end
end
@@ -100,7 +89,15 @@ module Gollum
# Returns the String HTML if the tag is a valid file link tag or nil
# if it is not.
def process_file_link_tag(tag)
nil
parts = tag.split('|')
name = parts[0].strip
path = parts[1] && parts[1].strip
if name && path && file = find_file(path)
%{<a href="/#{file.path}">#{name}</a>}
else
nil
end
end
# Attempt to process the tag as a page link tag.
@@ -115,5 +112,19 @@ module Gollum
cname = Gollum::canonical_name((parts[1] || parts[0]).strip)
%{<a href="#{cname}">#{name}</a>}
end
# Find the given file in the repo.
#
# name - The String absolute or relative path of the file.
#
# Returns the Gollum::File or nil if none was found.
def find_file(name)
if name =~ /^\//
@wiki.file(name[1..-1], @version)
else
path = ::File.join(@dir, name)
@wiki.file(path, @version)
end
end
end
end