Allow base path to be specified for wiki links.
This commit is contained in:
@@ -231,6 +231,10 @@ Initialize the Gollum::Repo object:
|
|||||||
wiki = Gollum::Wiki.new("my-gollum-repo.git")
|
wiki = Gollum::Wiki.new("my-gollum-repo.git")
|
||||||
# => <Gollum::Wiki>
|
# => <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:
|
Get the latest version of the given human or canonical page name:
|
||||||
|
|
||||||
page = wiki.page('page-name')
|
page = wiki.page('page-name')
|
||||||
|
|||||||
@@ -202,11 +202,9 @@ module Gollum
|
|||||||
parts = tag.split('|')
|
parts = tag.split('|')
|
||||||
name = parts[0].strip
|
name = parts[0].strip
|
||||||
cname = Page.cname((parts[1] || parts[0]).strip)
|
cname = Page.cname((parts[1] || parts[0]).strip)
|
||||||
if @wiki.page(cname)
|
link = ::File.join(@wiki.base_path, cname)
|
||||||
%{<a class="internal present" href="#{cname}">#{name}</a>}
|
presence = @wiki.page(cname) ? "present" : "absent"
|
||||||
else
|
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
|
||||||
%{<a class="internal absent" href="#{cname}">#{name}</a>}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find the given file in the repo.
|
# Find the given file in the repo.
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ module Gollum
|
|||||||
attr_accessor :page_class, :file_class
|
attr_accessor :page_class, :file_class
|
||||||
end
|
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.
|
# Public: Initialize a new Gollum Repo.
|
||||||
#
|
#
|
||||||
# repo - The String path to the Git repository that holds the Gollum
|
# repo - The String path to the Git repository that holds the Gollum
|
||||||
@@ -18,6 +23,7 @@ module Gollum
|
|||||||
def initialize(path, options = {})
|
def initialize(path, options = {})
|
||||||
@path = path
|
@path = path
|
||||||
@repo = Grit::Repo.new(path)
|
@repo = Grit::Repo.new(path)
|
||||||
|
@base_path = options[:base_path] || "/"
|
||||||
@page_class = options[:page_class] || self.class.page_class
|
@page_class = options[:page_class] || self.class.page_class
|
||||||
@file_class = options[:file_class] || self.class.file_class
|
@file_class = options[:file_class] || self.class.file_class
|
||||||
end
|
end
|
||||||
|
|||||||
+14
-3
@@ -21,7 +21,7 @@ context "Markup" do
|
|||||||
|
|
||||||
page = @wiki.page("Bilbo Baggins")
|
page = @wiki.page("Bilbo Baggins")
|
||||||
output = Gollum::Markup.new(page).render
|
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
|
end
|
||||||
|
|
||||||
test "absent page link" do
|
test "absent page link" do
|
||||||
@@ -29,7 +29,18 @@ context "Markup" do
|
|||||||
|
|
||||||
page = @wiki.page("Tolkien")
|
page = @wiki.page("Tolkien")
|
||||||
output = Gollum::Markup.new(page).render
|
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
|
end
|
||||||
|
|
||||||
test "image with http url" do
|
test "image with http url" do
|
||||||
@@ -190,7 +201,7 @@ context "Markup" do
|
|||||||
|
|
||||||
test "quoted wiki link" do
|
test "quoted wiki link" do
|
||||||
content = "a '[[Foo]]', b"
|
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)
|
compare(content, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user