Add delete this Page based on .com.

Match short sha commit message of .com for edit and delete.
Update tests.
This commit is contained in:
bootstraponline
2012-07-21 15:33:43 -06:00
parent 77fb5ec3cb
commit e0b7009bff
6 changed files with 52 additions and 13 deletions
+16 -3
View File
@@ -125,7 +125,9 @@ module Precious
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
page = wiki.page(CGI.unescape(params[:page]))
name = params[:rename] || page.name
committer = Gollum::Committer.new(wiki, commit_message)
msg = commit_message
msg[:message]= msg[:message] + " [#{page.version_short}]"
committer = Gollum::Committer.new(wiki, msg)
commit = {:committer => committer}
update_wiki_page(wiki, page, params[:content], commit, name, params[:format])
@@ -139,6 +141,17 @@ module Precious
redirect "/#{page.escaped_url_path}"
end
get '/delete/*' do
@path = extract_path(params[:splat].first)
@name = extract_name(params[:splat].first).to_url
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
@page = wiki.page(@name)
wiki.delete_page(@page, { :message => "Destroyed #{@name} (#{@page.format}) [#{@page.version_short}]" })
redirect '/'
end
get '/create/*' do
@path = extract_path(params[:splat].first)
@name = extract_name(params[:splat].first).to_url
@@ -331,13 +344,13 @@ module Precious
end
end
def update_wiki_page(wiki, page, content, commit_message, name = nil, format = nil)
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
return if !page ||
((!content || page.raw_data == content) && page.format == format)
name ||= page.name
format = (format || page.format).to_sym
content ||= page.raw_data
wiki.update_page(page, name, format, content.to_s, commit_message)
wiki.update_page(page, name, format, content.to_s, commit)
end
def commit_message
@@ -1,5 +1,21 @@
// ua
$(document).ready(function() {
$('#delete-link').click( function(e) {
var ok = confirm($(this).data('confirm'));
if ( ok ) {
var href = window.location.href;
var index = href.lastIndexOf('/');
// /home
var page = href.substr(index);
// http://localhost:4567/
var host = href.substr(0, index+1);
var loc = host + 'delete' + page;
window.location = loc;
}
// Don't navigate on cancel.
e.preventDefault();
} );
var nodeSelector = {
node1: null,
node2: null,
@@ -57,5 +57,8 @@
</div>
<div id="footer">
<p id="last-edit">Last edited by <b>{{author}}</b>, {{date}}</p>
<p>
<a id="delete-link" href="{{escaped_url_path}}" data-confirm="Are you sure you want to delete this page?"><span>Delete this Page</span></a>
</p>
</div>
</div>
+7
View File
@@ -259,6 +259,13 @@ module Gollum
end
end
# Public: The first 7 characters of the current version.
#
# Returns the first 7 characters of the current version.
def version_short
version.to_s[0,7]
end
# Public: The header Page.
#
# Returns the header Page or nil if none exists.