Sinatra base url to allow subdirectories
This commit is contained in:
@@ -67,6 +67,10 @@ module Precious
|
||||
enable :logging, :raise_errors, :dump_errors
|
||||
end
|
||||
|
||||
before do
|
||||
@base_url = url('/')
|
||||
end
|
||||
|
||||
get '/' do
|
||||
show_page_or_file('Home')
|
||||
end
|
||||
@@ -93,7 +97,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
|
||||
@@ -122,7 +126,7 @@ module Precious
|
||||
|
||||
page = wiki.page(params[:rename]) if params[:rename]
|
||||
|
||||
redirect "/#{page.escaped_url_path}"
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
end
|
||||
|
||||
get '/create/*' do
|
||||
@@ -146,7 +150,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
|
||||
@@ -164,7 +168,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]
|
||||
@@ -201,12 +205,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
|
||||
|
||||
|
||||
@@ -62,16 +62,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;
|
||||
@@ -86,14 +86,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;
|
||||
@@ -101,7 +101,7 @@ 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -116,7 +116,7 @@ $(document).ready(function() {
|
||||
var name = res['name'];
|
||||
}
|
||||
|
||||
var url = '';
|
||||
var url = baseUrl;
|
||||
var path = $('#minibutton-new-page').data('path');
|
||||
if (path) {
|
||||
url += '/' + encodeURIComponent(path)
|
||||
|
||||
@@ -57,6 +57,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,7 +97,7 @@ $.save = function( commitMessage ) {
|
||||
var txt = editorSession.getValue();
|
||||
var msg = defaultCommitMessage();
|
||||
|
||||
var newLocation = location.protocol + '//' + location.host;
|
||||
var newLocation = location.protocol + '//' + location.host + baseUrl;
|
||||
if (pathName) {
|
||||
newLocation += '/' + pathName;
|
||||
}
|
||||
@@ -330,7 +333,7 @@ var applyTimeout = function () {
|
||||
/* Load markdown from /data/page into the ace editor. */
|
||||
jQuery.ajax( {
|
||||
type: 'GET',
|
||||
url: '/data/' + $.key( 'page' ),
|
||||
url: baseUrl + '/data/' + $.key( 'page' ),
|
||||
success: function( data ) {
|
||||
editorSession.setValue( data );
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
<li class="minibutton"><a href="/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
<li class="minibutton"><a href="/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}edit/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit Page</a></li>
|
||||
<li class="minibutton"><a href="/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}history/{{escaped_url_path}}"
|
||||
class="action-page-history">Page History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
{{#show_revert}}
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}history/{{escaped_url_path}}"
|
||||
class="action-page-history">Back to Page History</a></li>
|
||||
<li class="minibutton">
|
||||
<form name="gollum-revert" action="/revert/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
||||
<form name="gollum-revert" action="{{base_url}}revert/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
||||
<a href="#" class="gollum-revert-button">Revert Changes</a>
|
||||
</form>
|
||||
</li>
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div id="footer">
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}history/{{escaped_url_path}}"
|
||||
class="action-page-history">Back to Page History</a></li>
|
||||
{{#show_revert}}
|
||||
<li class="minibutton">
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<div id="head">
|
||||
<h1>Editing <strong>{{title}}</strong></h1>
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
<li class="minibutton"><a href="/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}history/{{escaped_url_path}}"
|
||||
class="action-page-history">Page History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<div id="gollum-editor" data-escaped-name="{{escaped_name}}" class="{{#is_create_page}}create{{/is_create_page}}{{#is_edit_page}}edit{{/is_edit_page}}">
|
||||
{{#is_create_page}}
|
||||
<form name="gollum-editor" action="/create" method="post">
|
||||
<form name="gollum-editor" action="{{base_url}}create" method="post">
|
||||
{{/is_create_page}}
|
||||
{{#is_edit_page}}
|
||||
<form name="gollum-editor" action="/edit/{{escaped_name}}" method="post">
|
||||
<form name="gollum-editor" action="{{base_url}}edit/{{escaped_name}}" method="post">
|
||||
{{/is_edit_page}}
|
||||
<fieldset id="gollum-editor-fields">
|
||||
{{#is_create_page}}
|
||||
@@ -126,7 +126,7 @@
|
||||
|
||||
<span class="jaws"><br></span>
|
||||
<input type="submit" id="gollum-editor-submit" value="Save" title="Save current changes">
|
||||
<a href="/preview" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||
<a href="{{base_url}}preview" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
|
||||
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="/css/gollum.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="/css/template.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="/css/_styles.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/gollum.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/template.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/_styles.css" media="all">
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -13,7 +12,7 @@
|
||||
<div id="home_button">
|
||||
<ul class="actions">
|
||||
<li class="minibutton">
|
||||
<a href="/" class="action-edit-page">Home</a>
|
||||
<a href="{{base_url}}" class="action-edit-page">Home</a>
|
||||
</li>
|
||||
<li class="minibutton" class="jaws">
|
||||
<a href="#" id="minibutton-new-page">New Page</a>
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
<li class="minibutton"><a href="/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
<li class="minibutton"><a href="/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}edit/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit Page</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -19,7 +19,7 @@
|
||||
</ul>
|
||||
|
||||
<form name="compare-versions" id="version-form" method="post"
|
||||
action="/compare/{{escaped_url_path}}">
|
||||
action="{{base_url}}compare/{{escaped_url_path}}">
|
||||
<fieldset>
|
||||
<table>
|
||||
<tbody>
|
||||
@@ -39,7 +39,7 @@
|
||||
<td class="commit-name">
|
||||
<span class="time-elapsed">{{date}}:</span>
|
||||
{{message}}
|
||||
[<a href="/{{escaped_url_path}}/{{id}}" title="View commit">{{id7}}</a>]
|
||||
[<a href="{{base_url}}{{escaped_url_path}}/{{id}}" title="View commit">{{id7}}</a>]
|
||||
</td>
|
||||
</tr>
|
||||
{{/versions}}
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="/css/gollum.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="/css/editor.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="/css/dialog.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="/css/template.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/gollum.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/editor.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/dialog.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/template.css" media="all">
|
||||
|
||||
<!--[if IE 7]>
|
||||
<link rel="stylesheet" type="text/css" href="/css/ie7.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="{{base_url}}css/ie7.css" media="all">
|
||||
<![endif]-->
|
||||
|
||||
<script>var baseUrl = '{{base_url}}'</script>
|
||||
<script type="text/javascript" src="{{base_url}}javascript/jquery.js"></script>
|
||||
<script type="text/javascript" src="{{base_url}}javascript/gollum.js"></script>
|
||||
<script type="text/javascript" src="{{base_url}}javascript/gollum.dialog.js"></script>
|
||||
<script type="text/javascript" src="{{base_url}}javascript/gollum.placeholder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/javascript/jquery.js"></script>
|
||||
<script type="text/javascript" src="/javascript/gollum.js"></script>
|
||||
<script type="text/javascript" src="/javascript/gollum.dialog.js"></script>
|
||||
<script type="text/javascript" src="/javascript/gollum.placeholder.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/javascript/editor/gollum.editor.js"></script>
|
||||
<script type="text/javascript" src="{{base_url}}javascript/editor/gollum.editor.js"></script>
|
||||
{{#mathjax}}<script type="text/javascript" src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>{{/mathjax}}
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
<li class="minibutton"><a href="/pages"
|
||||
<li class="minibutton"><a href="{{base_url}}pages"
|
||||
class="action-all-pages">All Pages</a></li>
|
||||
<li class="minibutton"><a href="/fileview"
|
||||
<li class="minibutton"><a href="{{base_url}}fileview"
|
||||
class="action-all-pages">File View</a></li>
|
||||
<li class="minibutton" class="jaws">
|
||||
<a href="#" id="minibutton-new-page">New Page</a></li>
|
||||
{{#editable}}
|
||||
<li class="minibutton"><a href="/edit/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}edit/{{escaped_url_path}}"
|
||||
class="action-edit-page">Edit Page</a></li>
|
||||
{{/editable}}
|
||||
<li class="minibutton"><a href="/history/{{escaped_url_path}}"
|
||||
<li class="minibutton"><a href="{{base_url}}history/{{escaped_url_path}}"
|
||||
class="action-page-history">Page History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
<li class="minibutton"><a href="/"
|
||||
<li class="minibutton"><a href="{{base_url}}"
|
||||
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>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
<li class="minibutton"><a href="/"
|
||||
<li class="minibutton"><a href="{{base_url}}"
|
||||
class="action-edit-page">Home</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -15,7 +15,7 @@
|
||||
<ul>
|
||||
{{#results}}
|
||||
<li>
|
||||
<a href="/{{name}}">{{name}}</a>
|
||||
<a href="{{base_url}}{{name}}">{{name}}</a>
|
||||
<span class="count">({{count}} matches)</span>
|
||||
</li>
|
||||
{{/results}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div id="searchbar">
|
||||
<form action="/search" method="get" id="search-form">
|
||||
<form action="{{base_url}}search" method="get" id="search-form">
|
||||
<div id="searchbar-fauxtext">
|
||||
<input type="text" name="q" id="search-query" value="Search…" autocomplete="off">
|
||||
<a href="#" id="search-submit" title="Search this wiki">
|
||||
|
||||
@@ -29,14 +29,16 @@ module Precious
|
||||
if @page_num == 1
|
||||
%(<span class="disabled">#{label}</span>)
|
||||
else
|
||||
%(<a href="/history/#{@page.name}?page=#{@page_num-1}" hotkey="h">#{label}</a>)
|
||||
link = url("/history/#{@page.name}?page=#{@page_num-1}")
|
||||
%(<a href="#{link}" hotkey="h">#{label}</a>)
|
||||
end
|
||||
end
|
||||
|
||||
def next_link
|
||||
label = "Next »"
|
||||
if @versions.size == Gollum::Page.per_page
|
||||
%(<a href="/history/#{@page.name}?page=#{@page_num+1}" hotkey="l">#{label}</a>)
|
||||
link = "/history/#{@page.name}?page=#{@page_num+1}"
|
||||
%(<a href="#{link}" hotkey="l">#{label}</a>)
|
||||
else
|
||||
%(<span class="disabled">#{label}</span>)
|
||||
end
|
||||
|
||||
@@ -16,14 +16,14 @@ module Precious
|
||||
def breadcrumb
|
||||
if @path
|
||||
path = Pathname.new(@path)
|
||||
breadcrumb = [%{<a href="/pages/">Home</a>}]
|
||||
breadcrumb = [%{<a href="#{@base_url}pages/">Home</a>}]
|
||||
path.descend do |crumb|
|
||||
title = crumb.basename
|
||||
|
||||
if title == path.basename
|
||||
breadcrumb << title
|
||||
else
|
||||
breadcrumb << %{<a href="/pages/#{crumb}/">#{title}</a>}
|
||||
breadcrumb << %{<a href="#{@base_url}pages/#{crumb}/">#{title}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ module Precious
|
||||
if page_path.include?('/')
|
||||
folder = page_path.split('/').first
|
||||
folder_path = @path ? "#{@path}/#{folder}" : folder
|
||||
folder_link = %{<li><a href="/pages/#{folder_path}/" class="folder">#{folder}</a></li>}
|
||||
folder_link = %{<li><a href="#{@base_url}pages/#{folder_path}/" class="folder">#{folder}</a></li>}
|
||||
|
||||
unless folder_links.include?(folder_link)
|
||||
folder_links << folder_link
|
||||
@@ -51,7 +51,7 @@ module Precious
|
||||
folder_link
|
||||
end
|
||||
elsif page_path != ".gitkeep"
|
||||
%{<li><a href="/#{page.escaped_url_path}" class="file">#{page.name}</a></li>}
|
||||
%{<li><a href="#{@base_url}#{page.escaped_url_path}" class="file">#{page.name}</a></li>}
|
||||
end
|
||||
}.compact.join("\n")
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user