Allow base path to be specified for wiki links.

This commit is contained in:
Tom Preston-Werner
2010-07-12 17:05:48 -07:00
parent 8f1100fbd6
commit baaa7c6b93
4 changed files with 27 additions and 8 deletions
+3 -5
View File
@@ -202,11 +202,9 @@ module Gollum
parts = tag.split('|')
name = parts[0].strip
cname = Page.cname((parts[1] || parts[0]).strip)
if @wiki.page(cname)
%{<a class="internal present" href="#{cname}">#{name}</a>}
else
%{<a class="internal absent" href="#{cname}">#{name}</a>}
end
link = ::File.join(@wiki.base_path, cname)
presence = @wiki.page(cname) ? "present" : "absent"
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
end
# Find the given file in the repo.
+6
View File
@@ -6,6 +6,11 @@ module Gollum
attr_accessor :page_class, :file_class
end
# The String base path to prefix to internal links. For example, when set
# to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
# to "/".
attr_reader :base_path
# Public: Initialize a new Gollum Repo.
#
# repo - The String path to the Git repository that holds the Gollum
@@ -18,6 +23,7 @@ module Gollum
def initialize(path, options = {})
@path = path
@repo = Grit::Repo.new(path)
@base_path = options[:base_path] || "/"
@page_class = options[:page_class] || self.class.page_class
@file_class = options[:file_class] || self.class.file_class
end