Implement Wiki#preview_page.
This commit is contained in:
@@ -383,6 +383,13 @@ Get a specific version of a given static file:
|
||||
|
||||
wiki.file('asset.js', '5ec521178e0eec4dc39741a8978a2ba6616d0f0a')
|
||||
|
||||
Get an in-memory Page preview (useful for generating previews for web
|
||||
interfaces):
|
||||
|
||||
preview = wiki.preview_page("My Page", "# Contents", :markdown)
|
||||
preview.formatted_data
|
||||
# => "<h1>Contents</h1>"
|
||||
|
||||
Methods that write to the repository require a Hash of commit data that takes
|
||||
the following form:
|
||||
|
||||
|
||||
@@ -84,6 +84,25 @@ module Gollum
|
||||
@file_class.new(self).find(name, version)
|
||||
end
|
||||
|
||||
# Public: Create an in-memory Page with the given data and format. This
|
||||
# is useful for previewing what content will look like before committing
|
||||
# it to the repository.
|
||||
#
|
||||
# name - The String name of the page.
|
||||
# format - The Symbol format of the page.
|
||||
# data - The new String contents of the page.
|
||||
#
|
||||
# Returns the in-memory Gollum::Page.
|
||||
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 = self.repo.commit("HEAD")
|
||||
page
|
||||
end
|
||||
|
||||
# Public: Write a new version of a page to the Gollum repo root.
|
||||
#
|
||||
# name - The String name of the page.
|
||||
|
||||
@@ -40,6 +40,20 @@ context "Wiki" do
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page previewing" do
|
||||
setup do
|
||||
@path = testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
test "preview_page" do
|
||||
page = @wiki.preview_page("Test", "# Bilbo", :markdown)
|
||||
assert_equal "# Bilbo", page.raw_data
|
||||
assert_equal "<h1>Bilbo</h1>", page.formatted_data
|
||||
assert_equal "Test.md", page.name
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page writing" do
|
||||
setup do
|
||||
@path = testpath("examples/test.git")
|
||||
|
||||
Reference in New Issue
Block a user