From 6e35a09abdacdac98dae58d071dab9fdba5a60b6 Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Fri, 22 Jun 2012 11:41:42 +0100 Subject: [PATCH] Add a 'New Page' button to the /pages browser that allows users to create a new page within a subdirectory. --- lib/gollum/frontend/app.rb | 1 + .../frontend/public/gollum/css/editor.css | 6 +++ .../public/gollum/javascript/gollum.js | 38 +++++++++++-------- lib/gollum/frontend/templates/editor.mustache | 3 ++ lib/gollum/frontend/templates/pages.mustache | 3 ++ lib/gollum/frontend/views/layout.rb | 4 ++ lib/gollum/frontend/views/pages.rb | 4 ++ test/test_pages_view.rb | 11 ++++++ 8 files changed, 54 insertions(+), 16 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index f8f379fa..5b9a77c5 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -299,6 +299,7 @@ module Precious file.raw_data else @name = name + @path = path mustache :create end end diff --git a/lib/gollum/frontend/public/gollum/css/editor.css b/lib/gollum/frontend/public/gollum/css/editor.css index 9003bc01..a590946b 100755 --- a/lib/gollum/frontend/public/gollum/css/editor.css +++ b/lib/gollum/frontend/public/gollum/css/editor.css @@ -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; diff --git a/lib/gollum/frontend/public/gollum/javascript/gollum.js b/lib/gollum/frontend/public/gollum/javascript/gollum.js index 2d832a9c..3c614dd3 100755 --- a/lib/gollum/frontend/public/gollum/javascript/gollum.js +++ b/lib/gollum/frontend/public/gollum/javascript/gollum.js @@ -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); + } + }); }); } diff --git a/lib/gollum/frontend/templates/editor.mustache b/lib/gollum/frontend/templates/editor.mustache index 2de7d7df..d81cd4ec 100644 --- a/lib/gollum/frontend/templates/editor.mustache +++ b/lib/gollum/frontend/templates/editor.mustache @@ -10,6 +10,9 @@
+ {{#has_path}} +

NOTE: This page will be created within the "{{path}}" directory

+ {{/has_path}}
{{/is_create_page}} {{#is_edit_page}} diff --git a/lib/gollum/frontend/templates/pages.mustache b/lib/gollum/frontend/templates/pages.mustache index f7d28307..eacfb9fa 100644 --- a/lib/gollum/frontend/templates/pages.mustache +++ b/lib/gollum/frontend/templates/pages.mustache @@ -7,6 +7,9 @@
  • Home
  • +
  • + New Page +
  • diff --git a/lib/gollum/frontend/views/layout.rb b/lib/gollum/frontend/views/layout.rb index 1b1aa2b9..65638176 100644 --- a/lib/gollum/frontend/views/layout.rb +++ b/lib/gollum/frontend/views/layout.rb @@ -15,6 +15,10 @@ module Precious def title "Home" end + + def has_path + !@path.nil? + end end end end diff --git a/lib/gollum/frontend/views/pages.rb b/lib/gollum/frontend/views/pages.rb index 3f5e8e9a..40ad4039 100644 --- a/lib/gollum/frontend/views/pages.rb +++ b/lib/gollum/frontend/views/pages.rb @@ -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) diff --git a/test/test_pages_view.rb b/test/test_pages_view.rb index 89b6f980..51b7c165 100644 --- a/test/test_pages_view.rb +++ b/test/test_pages_view.rb @@ -32,4 +32,15 @@ context "Precious::Views::Pages" do @page.instance_variable_set("@results", results) assert_equal %{
  • Eye Of Sauron
  • \n
  • Orc
  • }, @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