move formatted vs raw into Page
This commit is contained in:
@@ -230,12 +230,15 @@ Initialize the Gollum::Repo object:
|
||||
gollum = Gollum::Wiki.new("my-gollum-repo.git")
|
||||
# => <Gollum::Wiki>
|
||||
|
||||
Get the latest HTML formatted version of the given canonical page name:
|
||||
Get the latest version of the given human or canonical page name:
|
||||
|
||||
page = gollum.formatted_page('page-name')
|
||||
page = gollum.page('page-name')
|
||||
# => <Gollum::Page>
|
||||
|
||||
page.data
|
||||
page.raw_data
|
||||
# => "# My wiki page"
|
||||
|
||||
page.formatted_data
|
||||
# => "<h1>My wiki page</h1>"
|
||||
|
||||
page.format
|
||||
@@ -247,20 +250,6 @@ Get the latest HTML formatted version of the given canonical page name:
|
||||
vsn.id
|
||||
# => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5'
|
||||
|
||||
Get the latest raw version of the given canonical page name:
|
||||
|
||||
gollum.raw_page('page-name')
|
||||
# => <Gollum::Page>
|
||||
|
||||
page.data
|
||||
# => "# My wiki page"
|
||||
|
||||
page.format
|
||||
# => :markdown
|
||||
|
||||
page.version
|
||||
# => <Gollum::Version>
|
||||
|
||||
Get a list of versions for a given canonical page name:
|
||||
|
||||
vsns = gollum.page_versions('page-name')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# external
|
||||
require 'grit'
|
||||
require 'github/markup'
|
||||
|
||||
# internal
|
||||
require 'gollum/wiki'
|
||||
|
||||
+17
-3
@@ -23,10 +23,24 @@ module Gollum
|
||||
self
|
||||
end
|
||||
|
||||
# The contents of the page.
|
||||
# The on-disk filename of the page.
|
||||
#
|
||||
# Returns the String name.
|
||||
def name
|
||||
self.blob.name rescue nil
|
||||
end
|
||||
|
||||
# The formatted contents of the page.
|
||||
#
|
||||
# Returns the String data.
|
||||
def data
|
||||
def formatted_data
|
||||
GitHub::Markup.render(self.blob.name, self.blob.data) rescue nil
|
||||
end
|
||||
|
||||
# The raw contents of the page.
|
||||
#
|
||||
# Returns the String data.
|
||||
def raw_data
|
||||
self.blob.data rescue nil
|
||||
end
|
||||
|
||||
@@ -65,7 +79,7 @@ module Gollum
|
||||
# Returns a Gollum::Page or nil if the page could not be found.
|
||||
def find(name)
|
||||
commit = self.wiki.repo.commits.first
|
||||
content = find_page_in_tree(commit.tree, name)
|
||||
find_page_in_tree(commit.tree, name)
|
||||
end
|
||||
|
||||
# private
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ module Gollum
|
||||
# name - The human or canonical String page name of the wiki page.
|
||||
#
|
||||
# Returns a Gollum::Page or nil if no matching page was found.
|
||||
def formatted_page(name)
|
||||
def page(name)
|
||||
Page.new(self).find(name)
|
||||
end
|
||||
end
|
||||
|
||||
+8
-6
@@ -7,21 +7,23 @@ context "Page" do
|
||||
|
||||
test "new page" do
|
||||
page = Gollum::Page.new(@wiki)
|
||||
assert_nil page.data
|
||||
assert_nil page.raw_data
|
||||
assert_nil page.formatted_data
|
||||
end
|
||||
|
||||
test "formatted page" do
|
||||
page = @wiki.formatted_page('Bilbo Baggins')
|
||||
test "get existing page" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert page.data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||
assert page.formatted_data =~ /<h1>Bilbo Baggins<\/h1>\n\n<p>Bilbo Baggins/
|
||||
assert_equal :markdown, page.format
|
||||
end
|
||||
|
||||
test "no page match" do
|
||||
assert_nil @wiki.formatted_page('I do not exist')
|
||||
assert_nil @wiki.page('I do not exist')
|
||||
end
|
||||
|
||||
test "no ext match" do
|
||||
assert_nil @wiki.formatted_page('Data')
|
||||
assert_nil @wiki.page('Data')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user