Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ce6b0ac095 | |||
| 420bb06988 | |||
| 20566f8acf | |||
| 1d5f69704a | |||
| 0da664299e | |||
| 6e8fb2b457 | |||
| d1c72a4ff3 | |||
| 0bf05392e4 | |||
| 7ecef0c045 | |||
| 33ca329253 | |||
| 01fa4770cb | |||
| b76257c49c | |||
| e2fbf22f38 |
+2
-2
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
||||
s.required_ruby_version = ">= 1.8.7"
|
||||
|
||||
s.name = 'gollum'
|
||||
s.version = '2.1.6'
|
||||
s.date = '2012-08-23'
|
||||
s.version = '2.1.7'
|
||||
s.date = '2012-08-25'
|
||||
s.rubyforge_project = 'gollum'
|
||||
|
||||
s.summary = "A simple, Git-powered wiki."
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ require File.expand_path('../gollum/tex', __FILE__)
|
||||
require File.expand_path('../gollum/web_sequence_diagram', __FILE__)
|
||||
|
||||
module Gollum
|
||||
VERSION = '2.1.6'
|
||||
VERSION = '2.1.7'
|
||||
|
||||
def self.assets_path
|
||||
::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
|
||||
|
||||
+23
-14
@@ -90,19 +90,26 @@ module Precious
|
||||
redirect File.join(settings.wiki_options[:base_path].to_s, 'Home')
|
||||
end
|
||||
|
||||
# Removes all slashes from the start of string.
|
||||
def clean_url url
|
||||
return url if url.nil?
|
||||
url.gsub('%2F','/').gsub(/^\/+/,'')
|
||||
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
|
||||
# extract_path will trim path to 'a'
|
||||
# name, path, version
|
||||
def wiki_page( name, path = nil, version = nil)
|
||||
def wiki_page(name, path = nil, version = nil, exact = true)
|
||||
path = name if path.nil?
|
||||
name = extract_name(name)
|
||||
path = extract_path(path)
|
||||
path = '/' if exact && path.nil?
|
||||
|
||||
wiki = wiki_new
|
||||
|
||||
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, version),
|
||||
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, exact, version),
|
||||
:name => name, :path => path)
|
||||
end
|
||||
|
||||
@@ -141,14 +148,14 @@ module Precious
|
||||
end
|
||||
|
||||
post '/edit/*' do
|
||||
wikip = wiki_page(CGI.unescape(params[:page]), sanitize_empty_params(params[:path]))
|
||||
path = wikip.path
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
rename = params[:rename].to_url if params[:rename]
|
||||
name = rename || page.name
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = {:committer => committer}
|
||||
path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s
|
||||
page_name = CGI.unescape(params[:page])
|
||||
wiki = wiki_new
|
||||
page = wiki.paged(page_name, path, exact = true)
|
||||
rename = params[:rename].to_url if params[:rename]
|
||||
name = rename || page.name
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = {:committer => committer}
|
||||
|
||||
update_wiki_page(wiki, page, params[:content], commit, name, params[:format])
|
||||
update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
|
||||
@@ -187,6 +194,7 @@ module Precious
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path])
|
||||
path = '' if path.nil?
|
||||
format = params[:format].intern
|
||||
|
||||
# write_page is not directory aware so use wiki_options to emulate dir support.
|
||||
@@ -195,8 +203,7 @@ module Precious
|
||||
|
||||
begin
|
||||
wiki.write_page(name, format, params[:content], commit_message)
|
||||
page = wiki.page(name)
|
||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||
redirect to("/#{clean_url(CGI.escape(::File.join(path,name)))}")
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
@@ -341,7 +348,9 @@ module Precious
|
||||
path = extract_path(fullpath)
|
||||
wiki = wiki_new
|
||||
|
||||
if page = wiki.paged(name, path)
|
||||
path = '/' if path.nil?
|
||||
|
||||
if page = wiki.paged(name, path, exact = true)
|
||||
@page = page
|
||||
@name = name
|
||||
@editable = true
|
||||
@@ -354,7 +363,7 @@ module Precious
|
||||
file.raw_data
|
||||
else
|
||||
page_path = [path, name].compact.join('/')
|
||||
redirect to("/create/#{encodeURIComponent(page_path).gsub('%2F','/')}")
|
||||
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -99,13 +99,21 @@ $.save = function( commitMessage ) {
|
||||
var msg = defaultCommitMessage();
|
||||
var newLocation = baseUrl;
|
||||
|
||||
function clean( str ) {
|
||||
return str.replace(/^\/+/g, '/');
|
||||
}
|
||||
|
||||
// 'a%2Fb' => a/b
|
||||
if (pathName) {
|
||||
newLocation += '/' + unescape(pathName);
|
||||
if ( pathName ) {
|
||||
pathName = unescape( pathName );
|
||||
newLocation += '/' + pathName;
|
||||
pathName = pathName + '/'; // pathName must end with /
|
||||
|
||||
pathName = clean( pathName );
|
||||
}
|
||||
|
||||
newLocation += '/' + pageName;
|
||||
newLocation = clean( newLocation );
|
||||
|
||||
// if &create=true then handle create instead of edit.
|
||||
if ( create ) {
|
||||
|
||||
+13
-3
@@ -228,7 +228,7 @@ module Gollum
|
||||
if is_preformatted?(data, id)
|
||||
data.gsub!(id, "[[#{tag}]]")
|
||||
else
|
||||
data.gsub!(id, process_tag(tag))
|
||||
data.gsub!(id, process_tag(tag).gsub('%2F', '/'))
|
||||
end
|
||||
end
|
||||
data
|
||||
@@ -441,13 +441,23 @@ module Gollum
|
||||
# Find a page from a given cname. If the page has an anchor (#) and has
|
||||
# no match, strip the anchor and try again.
|
||||
#
|
||||
# cname - The String canonical page name.
|
||||
# cname - The String canonical page name including path.
|
||||
#
|
||||
# Returns a Gollum::Page instance if a page is found, or an Array of
|
||||
# [Gollum::Page, String extra] if a page without the extra anchor data
|
||||
# is found.
|
||||
def find_page_from_name(cname)
|
||||
if page = @wiki.page(cname)
|
||||
slash = cname.rindex('/')
|
||||
|
||||
unless slash.nil?
|
||||
name = cname[slash+1..-1]
|
||||
path = cname[0..slash]
|
||||
page = @wiki.paged(name, path)
|
||||
else
|
||||
page = @wiki.paged(cname, '/')
|
||||
end
|
||||
|
||||
if page
|
||||
return page
|
||||
end
|
||||
if pos = cname.index('#')
|
||||
|
||||
+6
-4
@@ -327,7 +327,7 @@ module Gollum
|
||||
# Returns the String canonical name.
|
||||
def self.cname(name, char_white_sub = '-', char_other_sub = '-')
|
||||
name.respond_to?(:gsub) ?
|
||||
name.gsub(%r{\s},char_white_sub).gsub(%r{[/<>+]}, char_other_sub) :
|
||||
name.gsub(%r{\s},char_white_sub).gsub(%r{[<>+]}, char_other_sub) :
|
||||
''
|
||||
end
|
||||
|
||||
@@ -372,9 +372,9 @@ module Gollum
|
||||
# version - The String version ID to find.
|
||||
#
|
||||
# Returns a Gollum::Page or nil if the page could not be found.
|
||||
def find(name, version, dir = nil)
|
||||
def find(name, version, dir = nil, exact = false)
|
||||
map = @wiki.tree_map_for(version.to_s)
|
||||
if page = find_page_in_tree(map, name, dir)
|
||||
if page = find_page_in_tree(map, name, dir, exact)
|
||||
page.version = version.is_a?(Grit::Commit) ?
|
||||
version : @wiki.commit_for(version)
|
||||
page.historical = page.version.to_s == version.to_s
|
||||
@@ -391,12 +391,14 @@ module Gollum
|
||||
# to be in. The string should
|
||||
#
|
||||
# Returns a Gollum::Page or nil if the page could not be found.
|
||||
def find_page_in_tree(map, name, checked_dir = nil)
|
||||
def find_page_in_tree(map, name, checked_dir = nil, exact = false)
|
||||
return nil if !map || name.to_s.empty?
|
||||
if checked_dir = BlobEntry.normalize_dir(checked_dir)
|
||||
checked_dir.downcase!
|
||||
end
|
||||
|
||||
checked_dir = '' if exact && checked_dir.nil?
|
||||
|
||||
map.each do |entry|
|
||||
next if entry.name.to_s.empty?
|
||||
next unless checked_dir.nil? || entry.dir.downcase == checked_dir
|
||||
|
||||
+4
-4
@@ -196,9 +196,9 @@ module Gollum
|
||||
# dir - The directory String relative to the repo.
|
||||
#
|
||||
# Returns a Gollum::Page or nil if no matching page was found.
|
||||
def page(name, version = @ref, dir = nil)
|
||||
def page(name, version = @ref, dir = nil, exact = false)
|
||||
version = @ref if version.nil?
|
||||
@page_class.new(self).find(name, version, dir)
|
||||
@page_class.new(self).find(name, version, dir, exact)
|
||||
end
|
||||
|
||||
# Public: Convenience method instead of calling page(name, nil, dir).
|
||||
@@ -208,8 +208,8 @@ module Gollum
|
||||
# dir - The directory String relative to the repo.
|
||||
#
|
||||
# Returns a Gollum::Page or nil if no matching page was found.
|
||||
def paged(name, dir = nil, version = @ref)
|
||||
page(name, version, dir)
|
||||
def paged(name, dir = nil, exact = false, version = @ref)
|
||||
page(name, version, dir, exact)
|
||||
end
|
||||
|
||||
# Public: Get the static file for a given name.
|
||||
|
||||
@@ -50,6 +50,14 @@ context "Frontend" do
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "edit page with slash" do
|
||||
page_1 = @wiki.page('A')
|
||||
post "/edit/A", :content => 'abc', :page => 'A', :path => '/////',
|
||||
:format => page_1.format, :message => 'def'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
test "edits page header footer and sidebar" do
|
||||
commits = @wiki.repo.commits('master').size
|
||||
page_1 = @wiki.page('A')
|
||||
@@ -176,6 +184,7 @@ context "Frontend" do
|
||||
name = "A"
|
||||
post "/create", :content => 'abc', :page => name,
|
||||
:format => 'markdown', :message => 'def'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
|
||||
@wiki.clear_cache
|
||||
|
||||
+2
-1
@@ -99,7 +99,8 @@ context "Page" do
|
||||
test "cname" do
|
||||
assert_equal "Foo", Gollum::Page.cname("Foo")
|
||||
assert_equal "Foo-Bar", Gollum::Page.cname("Foo Bar")
|
||||
assert_equal "Foo---Bar", Gollum::Page.cname("Foo / Bar")
|
||||
# / is now a directory delimiter so it must be preserved
|
||||
assert_equal "Foo-/-Bar", Gollum::Page.cname("Foo / Bar")
|
||||
assert_equal "José", Gollum::Page.cname("José")
|
||||
assert_equal "モルドール", Gollum::Page.cname("モルドール")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user