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
+4
View File
@@ -231,6 +231,10 @@ Initialize the Gollum::Repo object:
wiki = Gollum::Wiki.new("my-gollum-repo.git")
# => <Gollum::Wiki>
By default, internal wiki links are all absolute from the root. To specify a different base path, you can send specify the `:base_path` option:
wiki = Gollum::Wiki.new("my-gollum-repo.git", :base_path => "/wiki")
Get the latest version of the given human or canonical page name:
page = wiki.page('page-name')
+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
+14 -3
View File
@@ -21,7 +21,7 @@ context "Markup" do
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <a class="internal present" href="Bilbo-Baggins">Bilbo Baggins</a> b</p>}, output
assert_equal %{<p>a <a class="internal present" href="/Bilbo-Baggins">Bilbo Baggins</a> b</p>}, output
end
test "absent page link" do
@@ -29,7 +29,18 @@ context "Markup" do
page = @wiki.page("Tolkien")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <a class="internal absent" href="J.-R.-R.-Tolkien">J. R. R. Tolkien</a>'s b</p>}, output
assert_equal %{<p>a <a class="internal absent" href="/J.-R.-R.-Tolkien">J. R. R. Tolkien</a>'s b</p>}, output
end
test "page link with custom base path" do
["/wiki", "/wiki/"].each do |path|
@wiki = Gollum::Wiki.new(@path, :base_path => path)
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", @commit)
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <a class="internal present" href="/wiki/Bilbo-Baggins">Bilbo Baggins</a> b</p>}, output
end
end
test "image with http url" do
@@ -190,7 +201,7 @@ context "Markup" do
test "quoted wiki link" do
content = "a '[[Foo]]', b"
output = "<p>a '<a class=\"internal absent\" href=\"Foo\">Foo</a>', b</p>"
output = "<p>a '<a class=\"internal absent\" href=\"/Foo\">Foo</a>', b</p>"
compare(content, output)
end