Repository page files with spaces, will now match using urls with hyphens, underscores and urlencoded spaces. This is for compatibility with mediawiki conversions.

This commit is contained in:
Arran Cudbard-Bell
2011-05-31 14:30:44 -07:00
committed by Arran Cudbard-Bell
parent 4abc32f1ec
commit af7a52970f
2 changed files with 25 additions and 8 deletions
+11 -5
View File
@@ -238,16 +238,21 @@ module Gollum
# Convert a human page name into a canonical page name. # Convert a human page name into a canonical page name.
# #
# name - The String human page name. # name - The String human page name.
# char_white_sub - Substitution for whitespace
# char_other_sub - Substitution for other special chars
# #
# Examples # Examples
# #
# Page.cname("Bilbo Baggins") # Page.cname("Bilbo Baggins")
# # => 'Bilbo-Baggins' # # => 'Bilbo-Baggins'
# #
# Page.cname("Bilbo Baggins",'_')
# # => 'Bilbo_Baggins'
#
# Returns the String canonical name. # Returns the String canonical name.
def self.cname(name) def self.cname(name, char_white_sub = '-', char_other_sub = '-')
name.respond_to?(:gsub) ? name.respond_to?(:gsub) ?
name.gsub(%r{[ /<>]}, '-') : name.gsub(%r{\s},char_white_sub).gsub(%r{[/<>+]}, char_other_sub) :
'' ''
end end
@@ -361,11 +366,12 @@ module Gollum
# Returns a Boolean. # Returns a Boolean.
def page_match(name, filename) def page_match(name, filename)
if match = self.class.valid_filename?(filename) if match = self.class.valid_filename?(filename)
Page.cname(name).downcase == Page.cname(match).downcase @wiki.ws_subs.each do |sub|
else return true if Page.cname(name).downcase == Page.cname(match, sub).downcase
false
end end
end end
false
end
# Loads a sub page. Sub page nanes (footers) are prefixed with # Loads a sub page. Sub page nanes (footers) are prefixed with
# an underscore to distinguish them from other Pages. # an underscore to distinguish them from other Pages.
+11
View File
@@ -21,6 +21,9 @@ module Gollum
# Sets the default email for commits. # Sets the default email for commits.
attr_accessor :default_committer_email attr_accessor :default_committer_email
# Array of chars to substitute whitespace for when trying to locate file in git repo.
attr_accessor :default_ws_subs
# Sets sanitization options. Set to false to deactivate # Sets sanitization options. Set to false to deactivate
# sanitization altogether. # sanitization altogether.
attr_writer :sanitization attr_writer :sanitization
@@ -87,6 +90,8 @@ module Gollum
self.default_committer_name = 'Anonymous' self.default_committer_name = 'Anonymous'
self.default_committer_email = 'anon@anon.com' self.default_committer_email = 'anon@anon.com'
self.default_ws_subs = ['_','-']
# The String base path to prefix to internal links. For example, when set # The String base path to prefix to internal links. For example, when set
# to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults # to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
# to "/". # to "/".
@@ -104,6 +109,9 @@ module Gollum
# Gets the String directory in which all page files reside. # Gets the String directory in which all page files reside.
attr_reader :page_file_dir attr_reader :page_file_dir
# Gets the Array of chars to sub for ws in filenames.
attr_reader :ws_subs
# Public: Initialize a new Gollum Repo. # Public: Initialize a new Gollum Repo.
# #
# path - The String path to the Git repository that holds the Gollum # path - The String path to the Git repository that holds the Gollum
@@ -117,6 +125,7 @@ module Gollum
# :sanitization - An instance of Sanitization. # :sanitization - An instance of Sanitization.
# :page_file_dir - String the directory in which all page files reside # :page_file_dir - String the directory in which all page files reside
# :ref - String the repository ref to retrieve pages from # :ref - String the repository ref to retrieve pages from
# :ws_subs - Array of chars to sub for ws in filenames.
# #
# Returns a fresh Gollum::Repo. # Returns a fresh Gollum::Repo.
def initialize(path, options = {}) def initialize(path, options = {})
@@ -134,6 +143,8 @@ module Gollum
@repo = @access.repo @repo = @access.repo
@ref = options[:ref] || self.class.default_ref @ref = options[:ref] || self.class.default_ref
@sanitization = options[:sanitization] || self.class.sanitization @sanitization = options[:sanitization] || self.class.sanitization
@ws_subs = options[:ws_subs] ||
self.class.default_ws_subs
@history_sanitization = options[:history_sanitization] || @history_sanitization = options[:history_sanitization] ||
self.class.history_sanitization self.class.history_sanitization
end end