Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed subdirectories

  • Loading branch information...
commit ea319bdf03680df4264dee8af31c633342a29bb2 1 parent 2e5c657
Maciej Wiśniowski authored
View
8 lib/gollum.rb
@@ -36,5 +36,13 @@ def initialize(dir, existing, attempted, message = nil)
super(message || "Cannot write #{@dir}/#{@attempted_path}, found #{@dir}/#{@existing_path}.")
end
end
+
+ def Gollum.split_url(name)
+ #require 'ruby-debug/debugger'
+ pathlist = name.split(IO::File::SEPARATOR)
+ dir = pathlist[0..-2].join('/')
+ stripped_name = pathlist[-1]
+ return dir + '/', Gollum::Page.cname(stripped_name)
+ end
end
View
13 lib/gollum/frontend/app.rb
@@ -66,7 +66,7 @@ class App < Sinatra::Base
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
committer.commit
- redirect "#{base_path}/#{CGI.escape(Gollum::Page.cname(name))}"
+ redirect "#{base_path}/#{page.url}"
end
post '/create' do
@@ -76,8 +76,9 @@ class App < Sinatra::Base
format = params[:format].intern
begin
- wiki.write_page(name, format, params[:content], commit_message)
- redirect "#{base_path}/#{CGI.escape(name)}"
+ dir, filename = Gollum::split_url(name)
+ wiki.write_page(dir, filename, format, params[:content], commit_message)
+ redirect "#{base_path}/#{dir}#{Gollum::Page.cname(filename)}"
rescue Gollum::DuplicatePageError => e
@message = "Duplicate page: #{e.message}"
mustache :error
@@ -93,7 +94,7 @@ class App < Sinatra::Base
sha2 = shas.shift
if wiki.revert_page(@page, sha1, sha2, commit_message)
- redirect "#{base_path}/#{CGI.escape(@name)}"
+ redirect "#{base_path}/#{@page.url}"
else
sha2, sha1 = sha1, "#{sha1}^" if !sha2
@versions = [sha1, sha2]
@@ -113,8 +114,8 @@ class App < Sinatra::Base
mustache :page
end
- get '/history/:name' do
- @name = params[:name]
+ get '/history/*' do
+ @name = params[:splat].first
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@page = wiki.page(@name)
@page_num = [params[:page].to_i, 1].max
View
5 lib/gollum/frontend/templates/page.mustache
@@ -7,14 +7,15 @@
<li class="minibutton" class="jaws">
<a href="#" id="minibutton-new-page">New Page</a></li>
{{#editable}}
- <li class="minibutton"><a href="{{base_path}}/edit/{{escaped_name}}"
+ <li class="minibutton"><a href="{{base_path}}/edit/{{page_url}}"
class="action-edit-page">Edit Page</a></li>
{{/editable}}
- <li class="minibutton"><a href="{{base_path}}/history/{{escaped_name}}"
+ <li class="minibutton"><a href="{{base_path}}/history/{{page_url}}"
class="action-page-history">Page History</a></li>
</ul>
{{>searchbar}}
</div>
+
<div id="wiki-content">
<div class="wrap {{#has_footer}} has-footer {{/has_footer}} {{#has_sidebar}} has-rightbar{{/has_sidebar}}">
<div id="wiki-body" class="gollum-{{format}}-content">
View
2  lib/gollum/frontend/templates/pages.mustache
@@ -13,7 +13,7 @@
<ul>
{{#results}}
<li>
- <a href="{{base_path}}/{{{dir}}}{{name}}">/{{{dir}}}{{name}}</a>
+ <a href="{{base_path}}/{{{url}}}">/{{{dir}}}{{name}}</a>
</li>
{{/results}}
</ul>
View
4 lib/gollum/frontend/views/layout.rb
@@ -12,6 +12,10 @@ def escaped_name
CGI.escape(@name)
end
+ def file_name
+ CGI.escape(Gollum::Page.cname(@name))
+ end
+
def title
"Home"
end
View
4 lib/gollum/frontend/views/page.rb
@@ -52,6 +52,10 @@ def sidebar_content
def sidebar_format
has_sidebar && @sidebar.format.to_s
end
+
+ def page_url
+ @page.url
+ end
end
end
end
View
14 lib/gollum/page.rb
@@ -83,6 +83,10 @@ def self.canonicalize_filename(filename)
filename.split('.')[0..-2].join('.').gsub('-', ' ')
end
+ def self.slugify(filename)
+ cname(filename.split('.')[0..-2].join('.'))
+ end
+
# Public: Initialize a page.
#
# wiki - The Gollum::Wiki in question.
@@ -118,6 +122,16 @@ def name
self.class.canonicalize_filename(filename)
end
+ # Public: returns slug - name prepared for url
+ def slug
+ self.class.slugify(filename)
+ end
+
+ def url
+ return dir + slug if dir
+ slug
+ end
+
# Public: If the first element of a formatted page is an <h1> tag it can
# be considered the title of the page and used in the display. If the
# first element is NOT an <h1> tag, the title will be constructed from the
View
11 lib/gollum/wiki.rb
@@ -203,7 +203,8 @@ def preview_page(name, data, format)
# Public: Write a new version of a page to the Gollum repo root.
#
- # name - The String name of the page.
+ # dir - path to the page (subdirectories)
+ # filename - The String name of the page.
# format - The Symbol format of the page.
# data - The new String contents of the page.
# commit - The commit Hash details:
@@ -219,7 +220,7 @@ def preview_page(name, data, format)
#
# Returns the String SHA1 of the newly written version, or the
# Gollum::Committer instance if this is part of a batch update.
- def write_page(name, format, data, commit = {})
+ def write_page(dir, filename, format, data, commit = {})
multi_commit = false
committer = if obj = commit[:committer]
@@ -228,12 +229,12 @@ def write_page(name, format, data, commit = {})
else
Committer.new(self, commit)
end
-
- committer.add_to_index('', name, format, data)
+
+ committer.add_to_index(dir, filename, format, data)
committer.after_commit do |index, sha|
@access.refresh
- index.update_working_dir('', name, format)
+ index.update_working_dir(dir, filename, format)
end
multi_commit ? committer : committer.commit
Please sign in to comment.
Something went wrong with that request. Please try again.