image tag with relative path

This commit is contained in:
Tom Preston-Werner
2010-04-19 11:10:26 -07:00
parent 5f037e5e47
commit 342edec448
2 changed files with 22 additions and 5 deletions
+8 -2
View File
@@ -12,6 +12,7 @@ module Gollum
@name = page.name
@data = page.raw_data
@version = page.version.id
@dir = ::File.dirname(page.path)
@tagmap = {}
end
@@ -78,12 +79,17 @@ module Gollum
if name =~ /^\//
if file = @wiki.file(name[1..-1], @version)
%{<img src="#{file.name}" />}
%{<img src="/#{file.name}" />}
else
nil
end
else
nil
path = ::File.join(@dir, name)
if file = @wiki.file(path, @version)
%{<img src="/#{path}" />}
else
nil
end
end
end
+14 -3
View File
@@ -24,15 +24,26 @@ context "Markup" do
assert_equal %{<p>a <a href="Bilbo-Baggins">Bilbo Baggins</a> b</p>\n}, output
end
test "image" do
test "image with absolute path" do
index = @wiki.repo.index
index.add("alpha.jpg", "hi")
index.commit("Add alpha.jpg")
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] b", @commit)
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <img src="alpha.jpg" /> b</p>\n}, output
assert_equal %{<p>a <img src="/alpha.jpg" /> b</p>\n}, output
end
test "image with relative path" do
index = @wiki.repo.index
index.add("greek/alpha.jpg", "hi")
index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] b")
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
output = Gollum::Markup.new(page).render
assert_equal %{<p>a <img src="/greek/alpha.jpg" /> b</p>\n}, output
end
end