Merge pull request #400 from nature/new_page_within_dir
Add a 'New Page' button to the /pages browser.
This commit is contained in:
@@ -299,6 +299,7 @@ module Precious
|
||||
file.raw_data
|
||||
else
|
||||
@name = name
|
||||
@path = path
|
||||
mustache :create
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,6 +64,12 @@ a {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
#gollum-editor .path_note {
|
||||
text-align: right;
|
||||
font-size: small;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
#gollum-editor-title-field input#gollum-editor-page-title {
|
||||
font-weight: bold;
|
||||
margin-top: 0;
|
||||
|
||||
@@ -102,22 +102,28 @@ $(document).ready(function() {
|
||||
$('#minibutton-new-page').click(function(e) {
|
||||
e.preventDefault();
|
||||
$.GollumDialog.init({
|
||||
title: 'Create New Page',
|
||||
fields: [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Page Name',
|
||||
type: 'text'
|
||||
}
|
||||
],
|
||||
OK: function( res ) {
|
||||
var n = 'New Page';
|
||||
if ( res['name'] )
|
||||
var n = res['name'];
|
||||
n = encodeURIComponent( n );
|
||||
window.location = '/' + n;
|
||||
}
|
||||
});
|
||||
title: 'Create New Page',
|
||||
fields: [
|
||||
{
|
||||
id: 'name',
|
||||
name: 'Page Name',
|
||||
type: 'text'
|
||||
}
|
||||
],
|
||||
OK: function( res ) {
|
||||
var name = 'New Page';
|
||||
if ( res['name'] ) {
|
||||
var name = res['name'];
|
||||
}
|
||||
|
||||
var url = '';
|
||||
var path = $('#minibutton-new-page').data('path');
|
||||
if (path) {
|
||||
url += '/' + encodeURIComponent(path)
|
||||
}
|
||||
window.location = url + '/' + encodeURIComponent(name);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
<div id="gollum-editor-title-field" class="singleline">
|
||||
<label for="page" class="jaws">Page Title</label>
|
||||
<input type="text" name="page" id="gollum-editor-page-title" value="{{page_name}}">
|
||||
{{#has_path}}
|
||||
<p class="path_note"><strong>NOTE:</strong> This page will be created within the "<strong>{{path}}</strong>" directory</p>
|
||||
{{/has_path}}
|
||||
</div>
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
</li>
|
||||
<li class="minibutton"><a href="/"
|
||||
class="action-edit-page">Home</a></li>
|
||||
<li class="minibutton" class="jaws">
|
||||
<a href="#" id="minibutton-new-page"{{{new_page_data_variables}}}>New Page</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="pages">
|
||||
|
||||
@@ -15,6 +15,10 @@ module Precious
|
||||
def title
|
||||
"Home"
|
||||
end
|
||||
|
||||
def has_path
|
||||
!@path.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,10 @@ module Precious
|
||||
"All pages in #{@ref}"
|
||||
end
|
||||
|
||||
def new_page_data_variables
|
||||
%{ data-path="#{@path}"} if @path
|
||||
end
|
||||
|
||||
def breadcrumb
|
||||
if @path
|
||||
path = Pathname.new(@path)
|
||||
|
||||
@@ -32,4 +32,15 @@ context "Precious::Views::Pages" do
|
||||
@page.instance_variable_set("@results", results)
|
||||
assert_equal %{<li><a href="/Mordor/Eye-Of-Sauron" class="file">Eye Of Sauron</a></li>\n<li><a href="/pages/Mordor/Orc/" class="folder">Orc</a></li>}, @page.files_folders
|
||||
end
|
||||
|
||||
test "new_page_data_variables within Home directory" do
|
||||
assert_equal nil, @page.new_page_data_variables
|
||||
end
|
||||
|
||||
test "new_page_data_variables within subdirectory" do
|
||||
@page.instance_variable_set("@path", "Mordor")
|
||||
assert_equal ' data-path="Mordor"', @page.new_page_data_variables
|
||||
@page.instance_variable_set("@path", "Mordor/Eye-Of-Sauron")
|
||||
assert_equal ' data-path="Mordor/Eye-Of-Sauron"', @page.new_page_data_variables
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user