Merge pull request #421 from nature/create_new_page_in_subdir
Make the 'New Page' button create pages in sub directories.
This commit is contained in:
@@ -128,10 +128,14 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
get '/create/*' do
|
get '/create/*' do
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
|
@path = extract_path(params[:splat].first)
|
||||||
@name = params[:splat].first
|
@name = extract_name(params[:splat].first)
|
||||||
if wiki.page(@name)
|
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||||
redirect "/#{CGI.escape(@name)}"
|
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||||
|
|
||||||
|
page = wiki.page(@name)
|
||||||
|
if page
|
||||||
|
redirect "/#{page.escaped_url_path}"
|
||||||
else
|
else
|
||||||
mustache :create
|
mustache :create
|
||||||
end
|
end
|
||||||
@@ -311,7 +315,8 @@ module Precious
|
|||||||
content_type file.mime_type
|
content_type file.mime_type
|
||||||
file.raw_data
|
file.raw_data
|
||||||
else
|
else
|
||||||
redirect "/create/#{CGI.escape(name)}"
|
page_path = [path, name].compact.join('/')
|
||||||
|
redirect "/create/#{CGI.escape(page_path).gsub('%2F','/')}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -101,27 +101,28 @@ $(document).ready(function() {
|
|||||||
$('#minibutton-new-page').removeClass('jaws');
|
$('#minibutton-new-page').removeClass('jaws');
|
||||||
$('#minibutton-new-page').click(function(e) {
|
$('#minibutton-new-page').click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
var path = $(this).data('path');
|
||||||
|
if (path) {
|
||||||
|
path = path + '/';
|
||||||
|
}
|
||||||
|
|
||||||
$.GollumDialog.init({
|
$.GollumDialog.init({
|
||||||
title: 'Create New Page',
|
title: 'Create New Page',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
id: 'name',
|
id: 'name',
|
||||||
name: 'Page Name',
|
name: 'Page Name',
|
||||||
type: 'text'
|
type: 'text',
|
||||||
|
defaultValue: path || ''
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
OK: function( res ) {
|
OK: function( res ) {
|
||||||
var name = 'New Page';
|
var name = 'New Page';
|
||||||
if ( res['name'] ) {
|
if ( res['name'] ) {
|
||||||
var name = res['name'];
|
name = res['name'];
|
||||||
}
|
}
|
||||||
|
window.location = '/' + encodeURIComponent(name);
|
||||||
var url = '';
|
|
||||||
var path = $('#minibutton-new-page').data('path');
|
|
||||||
if (path) {
|
|
||||||
url += '/' + encodeURIComponent(path)
|
|
||||||
}
|
|
||||||
window.location = url + '/' + encodeURIComponent(name);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-44
@@ -116,12 +116,6 @@ context "Frontend" do
|
|||||||
assert_equal 'http://example.org/Title-with-spaces', last_response.headers['Location']
|
assert_equal 'http://example.org/Title-with-spaces', last_response.headers['Location']
|
||||||
get "/Title-with-spaces"
|
get "/Title-with-spaces"
|
||||||
assert_match /abc/, last_response.body
|
assert_match /abc/, last_response.body
|
||||||
|
|
||||||
post "/create", :content => 'ghi', :page => 'Title/with/slashes',
|
|
||||||
:format => 'markdown', :message => 'bar'
|
|
||||||
assert_equal 'http://example.org/Title-with-slashes', last_response.headers['Location']
|
|
||||||
get "/Title-with-slashes"
|
|
||||||
assert_match /ghi/, last_response.body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "redirects to create on non-existant page" do
|
test "redirects to create on non-existant page" do
|
||||||
@@ -216,41 +210,6 @@ context "Frontend" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# WTF? Surely this test is wrong...
|
|
||||||
# In this test repo there is already a file called 'bar.md'.
|
|
||||||
# This SHOULD raise a Duplicate Page error, no?
|
|
||||||
# context "Frontend with page-file-dir" do
|
|
||||||
# include Rack::Test::Methods
|
|
||||||
|
|
||||||
# setup do
|
|
||||||
# @path = cloned_testpath("examples/page_file_dir.git")
|
|
||||||
# @wiki = Gollum::Wiki.new(@path, { :page_file_dir => "docs" })
|
|
||||||
# Precious::App.set(:gollum_path, @path)
|
|
||||||
# Precious::App.set(:wiki_options, { :page_file_dir => "docs" })
|
|
||||||
# end
|
|
||||||
|
|
||||||
# teardown do
|
|
||||||
# FileUtils.rm_rf(@path)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# test "open existing parent" do
|
|
||||||
# get "/"
|
|
||||||
# assert last_response.ok?
|
|
||||||
|
|
||||||
# post "/create", :content => "asdf", :page => "bar",
|
|
||||||
# :format => 'markdown'
|
|
||||||
# follow_redirect!
|
|
||||||
# assert last_response.ok?
|
|
||||||
|
|
||||||
# # Assert not match.
|
|
||||||
# assert_equal true, /Duplicate page/.match(last_response.body) == nil
|
|
||||||
# end
|
|
||||||
|
|
||||||
# def app
|
|
||||||
# Precious::App
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
context "Frontend with lotr" do
|
context "Frontend with lotr" do
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
@@ -320,10 +279,10 @@ context "Frontend with lotr" do
|
|||||||
get "/Mordor/Orc"
|
get "/Mordor/Orc"
|
||||||
assert_match /big smelly creatures/, last_response.body
|
assert_match /big smelly creatures/, last_response.body
|
||||||
|
|
||||||
post "/create", :content => 'really big smelly creatures', :page => 'Orc/Uruk-hai',
|
post "/create", :content => 'really big smelly creatures', :page => 'Uruk Hai',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
||||||
assert_equal 'http://example.org/Mordor/Orc-Uruk-hai', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Uruk-Hai', last_response.headers['Location']
|
||||||
get "/Mordor/Orc-Uruk-hai"
|
get "/Mordor/Uruk-Hai"
|
||||||
assert_match /really big smelly creatures/, last_response.body
|
assert_match /really big smelly creatures/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user