Make the 'New Page' button create pages in sub directories if the user puts a slash in the path/page name.
This commit is contained in:
@@ -126,17 +126,21 @@ module Precious
|
||||
|
||||
redirect "/#{page.escaped_url_path}"
|
||||
end
|
||||
|
||||
|
||||
get '/create/*' do
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
||||
@name = params[:splat].first
|
||||
if wiki.page(@name)
|
||||
redirect "/#{CGI.escape(@name)}"
|
||||
@path = extract_path(params[:splat].first)
|
||||
@name = extract_name(params[:splat].first)
|
||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||
|
||||
page = wiki.page(@name)
|
||||
if page
|
||||
redirect "/#{page.escaped_url_path}"
|
||||
else
|
||||
mustache :create
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
post '/create' do
|
||||
name = params[:page]
|
||||
path = sanitize_empty_params(params[:path])
|
||||
@@ -311,7 +315,8 @@ module Precious
|
||||
content_type file.mime_type
|
||||
file.raw_data
|
||||
else
|
||||
redirect "/create/#{CGI.escape(name)}"
|
||||
page_path = [path, name].compact.join('/')
|
||||
redirect "/create/#{CGI.escape(page_path).gsub('%2F','/')}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -101,27 +101,28 @@ $(document).ready(function() {
|
||||
$('#minibutton-new-page').removeClass('jaws');
|
||||
$('#minibutton-new-page').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var path = $(this).data('path');
|
||||
if (path) {
|
||||
path = path + '/';
|
||||
}
|
||||
|
||||
$.GollumDialog.init({
|
||||
title: 'Create New Page',
|
||||
fields: [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Page Name',
|
||||
type: 'text'
|
||||
type: 'text',
|
||||
defaultValue: path || ''
|
||||
}
|
||||
],
|
||||
OK: function( res ) {
|
||||
var name = 'New Page';
|
||||
if ( res['name'] ) {
|
||||
var name = res['name'];
|
||||
name = res['name'];
|
||||
}
|
||||
|
||||
var url = '';
|
||||
var path = $('#minibutton-new-page').data('path');
|
||||
if (path) {
|
||||
url += '/' + encodeURIComponent(path)
|
||||
}
|
||||
window.location = url + '/' + encodeURIComponent(name);
|
||||
window.location = '/' + encodeURIComponent(name);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user