lib/gollum/frontend/app.rb in gollum-2.3.3 vs lib/gollum/frontend/app.rb in gollum-2.3.4
- old
+ new
@@ -1,5 +1,6 @@
+# ~*~ encoding: utf-8 ~*~
require 'cgi'
require 'sinatra'
require 'gollum'
require 'mustache/sinatra'
require 'useragent'
@@ -80,15 +81,16 @@
enable :logging, :raise_errors, :dump_errors
end
before do
@base_url = url('/', false).chomp('/')
- settings.wiki_options.merge!({ :base_path => @base_url }) unless settings.wiki_options.has_key? :base_path
+ # above will detect base_path when it's used with map in a config.ru
+ settings.wiki_options.merge!({ :base_path => @base_url })
end
get '/' do
- redirect File.join(settings.wiki_options[:page_file_dir].to_s,settings.wiki_options[:base_path].to_s, 'Home')
+ redirect ::File.join(@base_url, 'Home')
end
# path is set to name if path is nil.
# if path is 'a/b' and a and b are dirs, then
# path must have a trailing slash 'a/b/' or
@@ -185,28 +187,24 @@
end
end
post '/create' do
name = params[:page].to_url
- path = sanitize_empty_params(params[:path])
- path = '' if path.nil?
+ path = sanitize_empty_params(params[:path]) || ''
format = params[:format].intern
- page_dir = File.join(settings.wiki_options[:page_file_dir].to_s,
- settings.wiki_options[:base_path].to_s)
- # Home is a special case.
- path = '' if name.downcase == 'home'
+ # ensure pages are created in page_file_dir
+ page_dir = settings.wiki_options[:page_file_dir].to_s
+ path = clean_url(::File.join(page_dir, path)) unless path.start_with?(page_dir)
- page_dir = File.join(page_dir, path)
-
# write_page is not directory aware so use wiki_options to emulate dir support.
- wiki_options = settings.wiki_options.merge({ :page_file_dir => page_dir })
+ wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
begin
wiki.write_page(name, format, params[:content], commit_message)
- redirect to("/#{clean_url(CGI.escape(::File.join(page_dir,name)))}")
+ redirect to("/#{clean_url(::File.join(path,name))}")
rescue Gollum::DuplicatePageError => e
@message = "Duplicate page: #{e.message}"
mustache :error
end
end
@@ -327,30 +325,33 @@
@ref = wiki.ref
mustache :pages
end
get '/fileview' do
- wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
- show_all = settings.wiki_options[:show_all]
+ wiki = wiki_new
+ options = settings.wiki_options
+ content = wiki.pages
# if showing all files include wiki.files
- # must pass wiki_options for both because
+ content += wiki.files if options[:show_all]
+
+ # must pass wiki_options to FileView
# --show-all and --collapse-tree can be set.
- @results = show_all ? Gollum::FileView.new(wiki.pages + wiki.files, settings.wiki_options).render_files :
- Gollum::FileView.new(wiki.pages, settings.wiki_options).render_files
+ @results = Gollum::FileView.new(content, options).render_files
@ref = wiki.ref
mustache :file_view, { :layout => false }
end
get '/*' do
show_page_or_file(params[:splat].first)
end
def show_page_or_file(fullpath)
name = extract_name(fullpath)
- path = extract_path(fullpath)
+ path = extract_path(fullpath) || '/'
wiki = wiki_new
- path = '/' if path.nil?
+ page_dir = settings.wiki_options[:page_file_dir].to_s
+ path = ::File.join(page_dir, path) unless path.start_with?(page_dir)
if page = wiki.paged(name, path, exact = true)
@page = page
@name = name
@editable = true