refactor page update logic

This commit is contained in:
rick
2010-12-09 16:29:43 -08:00
parent 511b62c5ab
commit 6edd327ff0
+13 -6
View File
@@ -55,12 +55,11 @@ module Precious
end
post '/edit/*' do
wiki = Gollum::Wiki.new(settings.gollum_path)
page = wiki.page(params[:splat].first)
name = params[:rename] || page.name
format = params[:format].intern
wiki.update_page(page, name, format, params[:content], commit_message)
wiki = Gollum::Wiki.new(settings.gollum_path)
page = wiki.page(params[:splat].first)
name = params[:rename] || page.name
update_wiki_page(wiki, page, params[:content], commit_message,
name, params[:format])
redirect "/#{CGI.escape(Gollum::Page.cname(name))}"
end
@@ -160,6 +159,14 @@ module Precious
end
end
def update_wiki_page(wiki, page, content, commit_message, name = nil, format = nil)
return if !page
return if page.raw_data == content
name ||= page.name
format = (format || page.format).to_sym
wiki.update_page(page, name, format, content, commit_message)
end
def commit_message
{ :message => params[:message] }
end