Fix page file dir
This commit is contained in:
+2
-1
@@ -41,7 +41,8 @@ Gem::Specification.new do |s|
|
|||||||
s.add_development_dependency('rack-test', '~> 0.6.2')
|
s.add_development_dependency('rack-test', '~> 0.6.2')
|
||||||
s.add_development_dependency('wikicloth', '~> 0.8.0')
|
s.add_development_dependency('wikicloth', '~> 0.8.0')
|
||||||
s.add_development_dependency('rake', '~> 0.9')
|
s.add_development_dependency('rake', '~> 0.9')
|
||||||
|
s.add_development_dependency('pry')
|
||||||
|
s.add_development_dependency('rb-readline')
|
||||||
# = MANIFEST =
|
# = MANIFEST =
|
||||||
s.files = %w[
|
s.files = %w[
|
||||||
Gemfile
|
Gemfile
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
redirect ::File.join(@base_url,'Home')
|
redirect ::File.join(@base_url, 'Home')
|
||||||
end
|
end
|
||||||
|
|
||||||
# path is set to name if path is nil.
|
# path is set to name if path is nil.
|
||||||
@@ -189,17 +189,20 @@ module Precious
|
|||||||
|
|
||||||
post '/create' do
|
post '/create' do
|
||||||
name = params[:page].to_url
|
name = params[:page].to_url
|
||||||
path = sanitize_empty_params(params[:path])
|
path = sanitize_empty_params(params[:path]) || ''
|
||||||
path = '' if path.nil?
|
|
||||||
format = params[:format].intern
|
format = params[:format].intern
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
# write_page is not directory aware so use wiki_options to emulate dir support.
|
# write_page is not directory aware so use wiki_options to emulate dir support.
|
||||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
wiki.write_page(name, format, params[:content], commit_message)
|
wiki.write_page(name, format, params[:content], commit_message)
|
||||||
redirect to("/#{clean_url(CGI.escape(::File.join(path,name)))}")
|
redirect to("/#{clean_url(::File.join(path,name))}")
|
||||||
rescue Gollum::DuplicatePageError => e
|
rescue Gollum::DuplicatePageError => e
|
||||||
@message = "Duplicate page: #{e.message}"
|
@message = "Duplicate page: #{e.message}"
|
||||||
mustache :error
|
mustache :error
|
||||||
@@ -343,10 +346,11 @@ module Precious
|
|||||||
|
|
||||||
def show_page_or_file(fullpath)
|
def show_page_or_file(fullpath)
|
||||||
name = extract_name(fullpath)
|
name = extract_name(fullpath)
|
||||||
path = extract_path(fullpath)
|
path = extract_path(fullpath) || '/'
|
||||||
wiki = wiki_new
|
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)
|
if page = wiki.paged(name, path, exact = true)
|
||||||
@page = page
|
@page = page
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Remove all slashes from the start of string.
|
# Remove all slashes from the start of string.
|
||||||
|
# Remove all double slashes
|
||||||
def clean_url url
|
def clean_url url
|
||||||
return url if url.nil?
|
return url if url.nil?
|
||||||
url.gsub('%2F','/').gsub(/^\/+/,'')
|
url.gsub('%2F','/').gsub(/^\/+/,'').gsub('//','/')
|
||||||
end
|
end
|
||||||
|
|
||||||
def trim_leading_slash url
|
def trim_leading_slash url
|
||||||
|
|||||||
Reference in New Issue
Block a user