make markup take page as the param
This commit is contained in:
@@ -4,13 +4,12 @@ module Gollum
|
|||||||
class Markup
|
class Markup
|
||||||
# Initialize a new Markup object.
|
# Initialize a new Markup object.
|
||||||
#
|
#
|
||||||
# name - The String filename of the page.
|
# page - The Gollum::Page.
|
||||||
# data - The String contents of the page.
|
|
||||||
#
|
#
|
||||||
# Returns a new Gollum::Markup object, ready for rendering.
|
# Returns a new Gollum::Markup object, ready for rendering.
|
||||||
def initialize(name, data)
|
def initialize(page)
|
||||||
@name = name
|
@name = page.name
|
||||||
@data = data
|
@data = page.raw_data
|
||||||
@tagmap = {}
|
@tagmap = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,6 +71,9 @@ module Gollum
|
|||||||
# Returns the String HTML if the tag is a valid image tag or nil
|
# Returns the String HTML if the tag is a valid image tag or nil
|
||||||
# if it is not.
|
# if it is not.
|
||||||
def process_image_tag(tag)
|
def process_image_tag(tag)
|
||||||
|
parts = tag.split('|')
|
||||||
|
name = parts[0].strip
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,8 +95,8 @@ module Gollum
|
|||||||
# if it is not.
|
# if it is not.
|
||||||
def process_page_link_tag(tag)
|
def process_page_link_tag(tag)
|
||||||
parts = tag.split('|')
|
parts = tag.split('|')
|
||||||
name = parts[0]
|
name = parts[0].strip
|
||||||
cname = Gollum::canonical_name(parts[1] || parts[0])
|
cname = Gollum::canonical_name((parts[1] || parts[0]).strip)
|
||||||
%{<a href="#{cname}">#{name}</a>}
|
%{<a href="#{cname}">#{name}</a>}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the String data.
|
# Returns the String data.
|
||||||
def formatted_data
|
def formatted_data
|
||||||
Gollum::Markup.new(@blob.name, @blob.data).render rescue nil
|
Gollum::Markup.new(self).render rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: The format of the page.
|
# Public: The format of the page.
|
||||||
|
|||||||
+18
-2
@@ -1,9 +1,25 @@
|
|||||||
require File.join(File.dirname(__FILE__), *%w[helper])
|
require File.join(File.dirname(__FILE__), *%w[helper])
|
||||||
|
|
||||||
context "Markup" do
|
context "Markup" do
|
||||||
|
setup do
|
||||||
|
@path = testpath("examples/test.git")
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
Grit::Repo.init_bare(@path)
|
||||||
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
|
|
||||||
|
commit = { :message => "Bilbo page",
|
||||||
|
:name => "Tom Preston-Werner",
|
||||||
|
:email => "tom@github.com" }
|
||||||
|
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", commit)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
|
||||||
|
end
|
||||||
|
|
||||||
test "page link" do
|
test "page link" do
|
||||||
data = "a [[Bilbo Baggins]] b"
|
page = @wiki.page("Bilbo Baggins")
|
||||||
output = Gollum::Markup.new("x.md", data).render
|
output = Gollum::Markup.new(page).render
|
||||||
assert_equal %{<p>a <a href="Bilbo-Baggins">Bilbo Baggins</a> b</p>\n}, output
|
assert_equal %{<p>a <a href="Bilbo-Baggins">Bilbo Baggins</a> b</p>\n}, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user