refactor page update logic
This commit is contained in:
@@ -58,9 +58,8 @@ module Precious
|
|||||||
wiki = Gollum::Wiki.new(settings.gollum_path)
|
wiki = Gollum::Wiki.new(settings.gollum_path)
|
||||||
page = wiki.page(params[:splat].first)
|
page = wiki.page(params[:splat].first)
|
||||||
name = params[:rename] || page.name
|
name = params[:rename] || page.name
|
||||||
format = params[:format].intern
|
update_wiki_page(wiki, page, params[:content], commit_message,
|
||||||
|
name, params[:format])
|
||||||
wiki.update_page(page, name, format, params[:content], commit_message)
|
|
||||||
|
|
||||||
redirect "/#{CGI.escape(Gollum::Page.cname(name))}"
|
redirect "/#{CGI.escape(Gollum::Page.cname(name))}"
|
||||||
end
|
end
|
||||||
@@ -160,6 +159,14 @@ module Precious
|
|||||||
end
|
end
|
||||||
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
|
def commit_message
|
||||||
{ :message => params[:message] }
|
{ :message => params[:message] }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user