More refactoring.
Fix delete.
This commit is contained in:
+36
-30
@@ -91,14 +91,15 @@ module Precious
|
||||
end
|
||||
|
||||
# name, path, version
|
||||
def wiki_page( name, path = nil, version = nil )
|
||||
def wiki_page( name, path = nil, version = nil)
|
||||
path = name if path.nil?
|
||||
|
||||
name = extract_name(name)
|
||||
path = extract_path(path)
|
||||
wiki = wiki_new
|
||||
|
||||
wiki.paged(name, path, version)
|
||||
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, version),
|
||||
:name => name, :path => path)
|
||||
end
|
||||
|
||||
def wiki_new
|
||||
@@ -106,17 +107,17 @@ module Precious
|
||||
end
|
||||
|
||||
get '/data/*' do
|
||||
if page = wiki_page(params[:splat].first)
|
||||
if page = wiki_page(params[:splat].first).page
|
||||
page.raw_data
|
||||
end
|
||||
end
|
||||
|
||||
get '/edit/*' do
|
||||
splat = params[:splat].first
|
||||
@name = extract_name(splat)
|
||||
@path = extract_path(splat)
|
||||
wiki = wiki_new
|
||||
if page = wiki.paged(@name, @path)
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = wikip.name
|
||||
@path = wikip.path
|
||||
wiki = wikip.wiki
|
||||
if page = wikip.page
|
||||
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
|
||||
live_preview_url = '/livepreview/index.html?page=' + encodeURIComponent(@name)
|
||||
if @path
|
||||
@@ -136,10 +137,10 @@ module Precious
|
||||
end
|
||||
|
||||
post '/edit/*' do
|
||||
path = extract_path(sanitize_empty_params(params[:path]))
|
||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||
page = wiki.page(CGI.unescape(params[:page]))
|
||||
wikip = wiki_page(CGI.unescape(params[:page]), sanitize_empty_params(params[:path]))
|
||||
path = wikip.path
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
rename = params[:rename].to_url if params[:rename]
|
||||
name = rename || page.name
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
@@ -157,20 +158,22 @@ module Precious
|
||||
end
|
||||
|
||||
get '/delete/*' do
|
||||
name = params[:splat].first
|
||||
page = wiki_page(params[:splat].first)
|
||||
wiki = wiki_new
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
wiki.delete_page(page, { :message => "Destroyed #{name} (#{page.format})" })
|
||||
|
||||
redirect to('/')
|
||||
end
|
||||
|
||||
get '/create/*' do
|
||||
@name = extract_name(params[:splat].first).to_url
|
||||
@path = extract_path(params[:splat].first)
|
||||
wiki = wiki_new
|
||||
splat = params[:splat].first
|
||||
wikip = wiki_page(extract_name(splat).to_url, splat)
|
||||
@name = wikip.name
|
||||
@path = wikip.path
|
||||
|
||||
page = wiki.paged(@name,@path)
|
||||
page = wikip.page
|
||||
if page
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
else
|
||||
@@ -183,6 +186,7 @@ module Precious
|
||||
path = sanitize_empty_params(params[:path])
|
||||
format = params[:format].intern
|
||||
|
||||
# write_page is not directory aware so use wiki_options to emulate dir support.
|
||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||
|
||||
@@ -197,9 +201,10 @@ module Precious
|
||||
end
|
||||
|
||||
post '/revert/:page/*' do
|
||||
@path = extract_path(params[:page])
|
||||
@name = extract_name(params[:page])
|
||||
wiki = wiki_new
|
||||
wikip = wiki_page(params[:page])
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name,@path)
|
||||
shas = params[:splat].first.split("/")
|
||||
sha1 = shas.shift
|
||||
@@ -218,7 +223,7 @@ module Precious
|
||||
end
|
||||
|
||||
post '/preview' do
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||
wiki = wiki_new
|
||||
@name = params[:page] || "Preview"
|
||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
||||
@content = @page.formatted_data
|
||||
@@ -229,7 +234,7 @@ module Precious
|
||||
end
|
||||
|
||||
get '/history/*' do
|
||||
@page = wiki_page(params[:splat].first)
|
||||
@page = wiki_page(params[:splat].first).page
|
||||
@page_num = [params[:page].to_i, 1].max
|
||||
@versions = @page.versions :page => @page_num
|
||||
mustache :history
|
||||
@@ -257,11 +262,12 @@ module Precious
|
||||
\.{2,3} # match .. or ...
|
||||
(.+) # match the second SHA1
|
||||
}x do |path, start_version, end_version|
|
||||
@path = extract_path(path)
|
||||
@name = extract_name(path)
|
||||
wikip = wiki_page(path)
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
@versions = [start_version, end_version]
|
||||
wiki = wiki_new
|
||||
@page = wiki.paged(@name,@path)
|
||||
wiki = wikip.wiki
|
||||
@page = wikip.page
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
mustache :compare
|
||||
@@ -282,7 +288,7 @@ module Precious
|
||||
name = extract_name(file_path)
|
||||
path = extract_path(file_path)
|
||||
version = params[:captures][1]
|
||||
if page = wiki_page(name, path, version)
|
||||
if page = wiki_page(name, path, version).page
|
||||
@page = page
|
||||
@name = name
|
||||
@content = page.formatted_data
|
||||
@@ -295,7 +301,7 @@ module Precious
|
||||
|
||||
get '/search' do
|
||||
@query = params[:q]
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||
wiki = wiki_new
|
||||
@results = wiki.search @query
|
||||
@name = @query
|
||||
mustache :search
|
||||
|
||||
Reference in New Issue
Block a user