diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 487700e2..be6cc10e 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -333,9 +333,9 @@ module Gollum # path - The String directory path of the page file. # # Returns the populated Gollum::Page. - def populate(blob, path) + def populate(blob, path=nil) @blob = blob - @path = (path + '/' + blob.name)[1..-1] + @path = "#{path}/#{blob.name}"[1..-1] self end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index dd362572..e8a65246 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -168,10 +168,10 @@ module Gollum def preview_page(name, data, format) page = @page_class.new(self) ext = @page_class.format_to_ext(format.to_sym) - path = @page_class.cname(name) + '.' + ext - blob = OpenStruct.new(:name => path, :data => data) - page.populate(blob, path) - page.version = @access.commit('HEAD') + name = @page_class.cname(name) + '.' + ext + blob = OpenStruct.new(:name => name, :data => data) + page.populate(blob) + page.version = @access.commit('master') page end diff --git a/test/test_markup.rb b/test/test_markup.rb index 4f759ca3..6c8db408 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -238,6 +238,27 @@ context "Markup" do assert_equal %{

a a b

}, output end + test "image with absolute path on a preview" do + @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki') + index = @wiki.repo.index + index.add("alpha.jpg", "hi") + index.commit("Add alpha.jpg") + + page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown) + assert_equal %{

a b

}, page.formatted_data + end + + test "image with relative path on a preview" do + @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki') + index = @wiki.repo.index + index.add("alpha.jpg", "hi") + index.add("greek/alpha.jpg", "hi") + index.commit("Add alpha.jpg") + + page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown) + assert_equal %{

a b

}, page.formatted_data + end + test "image with alt" do content = "a [[alpha.jpg|alt=Alpha Dog]] b" output = %{

a Alpha Dog b

}