implement Wiki#write_page
This commit is contained in:
@@ -4,6 +4,23 @@ module Gollum
|
||||
|
||||
attr_accessor :wiki, :blob, :path, :version
|
||||
|
||||
# Convert a format Symbol into an extension String.
|
||||
#
|
||||
# format - The format Symbol.
|
||||
#
|
||||
# Returns the String extension (no leading period).
|
||||
def self.format_to_ext(format)
|
||||
case format
|
||||
when :markdown then 'md'
|
||||
when :textile then 'textile'
|
||||
when :rdoc then 'rdoc'
|
||||
when :org then 'org'
|
||||
when :rest then 'rest'
|
||||
when :asciidoc then 'asciidoc'
|
||||
when :pod then 'pod'
|
||||
end
|
||||
end
|
||||
|
||||
# Initialize a page.
|
||||
#
|
||||
# wiki - The Gollum::Wiki in question.
|
||||
|
||||
@@ -31,5 +31,24 @@ module Gollum
|
||||
def file(name, version = 'master')
|
||||
File.new(self).find(name, version)
|
||||
end
|
||||
|
||||
# Write a new version of a page to the Gollum repo root.
|
||||
#
|
||||
# name - The String name of the page.
|
||||
# data - The new String contents of the page.
|
||||
# commit - The commit Hash details { :message => String,
|
||||
# :author => String,
|
||||
# :email => String }
|
||||
#
|
||||
# Returns the String SHA1 of the newly written version.
|
||||
def write_page(name, format, data, commit = {})
|
||||
ext = Page.format_to_ext(format)
|
||||
path = Gollum.canonical_name(name) + '.' + ext
|
||||
index = self.repo.index
|
||||
index.add(path, data)
|
||||
actor = Grit::Actor.new(commit[:name], commit[:email])
|
||||
parent = self.repo.commit('master')
|
||||
index.commit(commit[:message], [parent], actor)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user