diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index e20e4d48..9e72c5ae 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -81,6 +81,11 @@ module Precious enable :logging, :raise_errors, :dump_errors end + before do + @base_url = url('/') + settings.wiki_options.merge!({ :base_path => @base_url }) unless settings.wiki_options.has_key? :base_path + end + get '/' do show_page_or_file('Home') end @@ -107,7 +112,7 @@ module Precious if @path live_preview_url << '&path=' + encodeURIComponent(@path) end - redirect live_preview_url + redirect to(live_preview_url) else @page = page @page.version = wiki.repo.log(wiki.ref, @page.path).first @@ -116,7 +121,7 @@ module Precious mustache :edit end else - redirect "/create/#{CGI.escape(@name)}" + redirect to("/create/#{CGI.escape(@name)}") end end @@ -138,7 +143,7 @@ module Precious page = wiki.page(rename) if rename - redirect "/#{page.escaped_url_path}" + redirect to("/#{page.escaped_url_path}") end get '/delete/*' do @@ -149,7 +154,7 @@ module Precious @page = wiki.page(@name) wiki.delete_page(@page, { :message => "Destroyed #{@name} (#{@page.format})" }) - redirect '/' + redirect to('/') end get '/create/*' do @@ -160,7 +165,7 @@ module Precious page = wiki.page(@name) if page - redirect "/#{page.escaped_url_path}" + redirect to("/#{page.escaped_url_path}") else mustache :create end @@ -177,7 +182,7 @@ module Precious begin wiki.write_page(name, format, params[:content], commit_message) page = wiki.page(name) - redirect "/#{page.escaped_url_path}" + redirect to("/#{page.escaped_url_path}") rescue Gollum::DuplicatePageError => e @message = "Duplicate page: #{e.message}" mustache :error @@ -195,7 +200,7 @@ module Precious sha2 = shas.shift if wiki.revert_page(@page, sha1, sha2, commit_message) - redirect "/#{@page.escaped_url_path}" + redirect to("/#{@page.escaped_url_path}") else sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] @@ -232,12 +237,13 @@ module Precious @file = params[:splat].first @versions = params[:versions] || [] if @versions.size < 2 - redirect "/history/#{@file}" + redirect to("/history/#{@file}") else - redirect "/compare/%s/%s...%s" % [ + redirect to("/compare/%s/%s...%s" % [ @file, @versions.last, @versions.first] + ) end end @@ -340,7 +346,7 @@ module Precious file.raw_data else page_path = [path, name].compact.join('/') - redirect "/create/#{CGI.escape(page_path).gsub('%2F','/')}" + redirect to("/create/#{CGI.escape(page_path).gsub('%2F','/')}") end end diff --git a/lib/gollum/frontend/public/gollum/css/_styles.css b/lib/gollum/frontend/public/gollum/css/_styles.css index 57461e84..092263c4 100644 --- a/lib/gollum/frontend/public/gollum/css/_styles.css +++ b/lib/gollum/frontend/public/gollum/css/_styles.css @@ -59,9 +59,9 @@ ol.tree padding: 0 0 0 30px; width: 300px; } - li - { - position: relative; + li + { + position: relative; margin-left: -15px; list-style: none; } @@ -72,16 +72,16 @@ ol.tree } li.file a { - background: url(/images/fileview/document.png) 0 0 no-repeat; + background: url(../images/fileview/document.png) 0 0 no-repeat; color: #fff; padding-left: 21px; text-decoration: none; display: block; } - li.file a[href *= '.pdf'] { background: url(/images/fileview/document.png) 0 0 no-repeat; } - li.file a[href *= '.html'] { background: url(/images/fileview/document.png) 0 0 no-repeat; } - li.file a[href $= '.css'] { background: url(/images/fileview/document.png) 0 0 no-repeat; } - li.file a[href $= '.js'] { background: url(/images/fileview/document.png) 0 0 no-repeat; } + li.file a[href *= '.pdf'] { background: url(../images/fileview/document.png) 0 0 no-repeat; } + li.file a[href *= '.html'] { background: url(../images/fileview/document.png) 0 0 no-repeat; } + li.file a[href $= '.css'] { background: url(../images/fileview/document.png) 0 0 no-repeat; } + li.file a[href $= '.js'] { background: url(../images/fileview/document.png) 0 0 no-repeat; } li input { position: absolute; @@ -96,14 +96,14 @@ ol.tree } li input + ol { - background: url(/images/fileview/toggle-small-expand.png) 40px 0 no-repeat; + background: url(../images/fileview/toggle-small-expand.png) 40px 0 no-repeat; margin: -1.188em 0 0 -44px; /* 15px */ height: 1.5em; } li input + ol > li { display: none; margin-left: -14px !important; padding-left: 1px; } li label { - background: url(/images/fileview/folder-horizontal.png) 15px 1px no-repeat; + background: url(../images/fileview/folder-horizontal.png) 15px 1px no-repeat; cursor: pointer; display: block; padding-left: 37px; @@ -111,10 +111,11 @@ ol.tree li input:checked + ol { - background: url(/images/fileview/toggle-small.png) 40px 5px no-repeat; + background: url(../images/fileview/toggle-small.png) 40px 5px no-repeat; margin: -1.5em 0 0 -44px; /* 20px */ padding: 1.563em 0 0 80px; height: auto; } li input:checked + ol > li { display: block; margin: 0 0 0.125em; /* 2px */} li input:checked + ol > li:last-child { margin: 0 0 0.063em; /* 1px */ } + diff --git a/lib/gollum/frontend/public/gollum/css/gollum.css b/lib/gollum/frontend/public/gollum/css/gollum.css index 96381b3b..c21bb723 100755 --- a/lib/gollum/frontend/public/gollum/css/gollum.css +++ b/lib/gollum/frontend/public/gollum/css/gollum.css @@ -662,7 +662,7 @@ ul.actions { } #head #searchbar #searchbar-fauxtext #search-submit span { - background-image: url(/images/icon-sprite.png); + background-image: url(../images/icon-sprite.png); background-position: -431px -1px; background-repeat: no-repeat; display: block; diff --git a/lib/gollum/frontend/public/gollum/css/template.css b/lib/gollum/frontend/public/gollum/css/template.css index 02959a32..7e9ff541 100644 --- a/lib/gollum/frontend/public/gollum/css/template.css +++ b/lib/gollum/frontend/public/gollum/css/template.css @@ -77,7 +77,7 @@ a.absent { .markdown-body h4:hover a.anchor, .markdown-body h5:hover a.anchor, .markdown-body h6:hover a.anchor { - background: url('/images/pin-20.png') no-repeat left center; + background: url(../images/pin-20.png) no-repeat left center; text-decoration: none; } .markdown-body h1 tt, @@ -133,7 +133,7 @@ a.absent { margin: 15px 0; } .markdown-body hr { - background: transparent url('/images/dirty-shade.png') repeat-x 0 0; + background: transparent url(../images/dirty-shade.png) repeat-x 0 0; border: 0 none; color: #ccc; height: 4px; diff --git a/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js index 53f24e31..d24af06f 100755 --- a/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js @@ -277,7 +277,7 @@ } // attempt to load the definition for this language - var script_uri = '/javascript/editor/langs/' + markup_name + '.js'; + var script_uri = baseUrl + '/javascript/editor/langs/' + markup_name + '.js'; $.ajax({ url: script_uri, dataType: 'script', diff --git a/lib/gollum/frontend/public/gollum/javascript/gollum.js b/lib/gollum/frontend/public/gollum/javascript/gollum.js index 0ba34c77..a24364d8 100755 --- a/lib/gollum/frontend/public/gollum/javascript/gollum.js +++ b/lib/gollum/frontend/public/gollum/javascript/gollum.js @@ -140,11 +140,11 @@ $(document).ready(function() { var msg = 'Renamed ' + oldName + ' to ' + name; jQuery.ajax( { type: 'POST', - url: '/edit/' + oldName, + url: baseUrl + '/edit/' + oldName, // omit path: pathName until https://github.com/github/gollum/issues/446 is fixed. data: { rename: name, page: oldName, message: msg }, success: function() { - window.location = '/' + encodeURIComponent(name); + window.location = baseUrl + '/' + encodeURIComponent(name); } }); } @@ -177,7 +177,7 @@ $(document).ready(function() { if ( res['name'] ) { name = res['name']; } - window.location = '/' + encodeURIComponent(name); + window.location = baseUrl + '/' + encodeURIComponent(name); } }); }); diff --git a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js index 11ab7232..c1941944 100644 --- a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +++ b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js @@ -58,6 +58,9 @@ var commentEditorContainer = commentEditor.container; initAce( commentEditor, commentEditorSession ); +// Find the app's base url, knowing we are in /livepreview/index.html +var baseUrl = location.pathname.split('/').slice(0,-2).join('/'); + // RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript $.key = function( key ) { var value = new RegExp( '[\\?&]' + key + '=([^]*)' ).exec( location.href ); @@ -94,19 +97,19 @@ $.save = function( commitMessage ) { var markdown = 'markdown'; var txt = editorSession.getValue(); var msg = defaultCommitMessage(); - var newLocation = location.protocol + '//' + location.host; + var newLocation = location.protocol + '//' + location.host + baseUrl; if (pathName) { newLocation += '/' + pathName; } - + newLocation += '/' + pageName; // if &create=true then handle create instead of edit. if ( create ) { jQuery.ajax( { type: POST, - url: '/create', + url: baseUrl + '/create', data: { path: pathName, page: pageName, format: markdown, content: txt, message: commitMessage || msg }, success: function() { win.location = newLocation; @@ -115,7 +118,7 @@ $.save = function( commitMessage ) { } else { jQuery.ajax( { type: POST, - url: '/edit/' + pageName, + url: baseUrl + '/edit/' + pageName, data: { path: pathName, page: pageName, format: markdown, content: txt, message: commitMessage || msg }, success: function() { win.location = newLocation; @@ -331,7 +334,7 @@ var applyTimeout = function () { if ( !~location.host.indexOf('github.com') ) { jQuery.ajax( { type: 'GET', - url: '/data/' + $.key( 'page' ), + url: baseUrl + '/data/' + $.key( 'page' ), success: function( data ) { editorSession.setValue( data ); } @@ -390,10 +393,10 @@ var applyTimeout = function () { var widthFourth = widthHalf / 2; var height = $( win ).height(); var heightHalf = height / 2; - + // height minus 50 so the end of document text doesn't flow off the page. var editorContainerStyle = 'width:' + widthHalf + 'px;' + - 'height:' + (height - 50) + 'px;' + + 'height:' + (height - 50) + 'px;' + 'left:' + (leftRight === false ? widthHalf + 'px;' : '0px;') + 'top:' + '40px;'; // use 40px for tool menu cssSet( editorContainer, editorContainerStyle ); diff --git a/lib/gollum/frontend/templates/compare.mustache b/lib/gollum/frontend/templates/compare.mustache index 4595f20e..55afc777 100644 --- a/lib/gollum/frontend/templates/compare.mustache +++ b/lib/gollum/frontend/templates/compare.mustache @@ -6,11 +6,11 @@