diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 1db0b83f..22bf778f 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -237,17 +237,22 @@ module Gollum # 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 # # Page.cname("Bilbo Baggins") # # => 'Bilbo-Baggins' # + # Page.cname("Bilbo Baggins",'_') + # # => 'Bilbo_Baggins' + # # Returns the String canonical name. - def self.cname(name) - name.respond_to?(:gsub) ? - name.gsub(%r{[ /<>]}, '-') : + 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) : '' end @@ -361,10 +366,11 @@ module Gollum # Returns a Boolean. def page_match(name, filename) if match = self.class.valid_filename?(filename) - Page.cname(name).downcase == Page.cname(match).downcase - else - false + @wiki.ws_subs.each do |sub| + return true if Page.cname(name).downcase == Page.cname(match, sub).downcase + end end + false end # Loads a sub page. Sub page nanes (footers) are prefixed with diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 8f042c5b..cef50981 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -20,7 +20,10 @@ module Gollum # Sets the default email for commits. 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 # sanitization altogether. attr_writer :sanitization @@ -86,6 +89,8 @@ module Gollum self.default_ref = 'master' self.default_committer_name = 'Anonymous' self.default_committer_email = 'anon@anon.com' + + self.default_ws_subs = ['_','-'] # 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 @@ -103,6 +108,9 @@ module Gollum # Gets the String directory in which all page files reside. 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. # @@ -117,6 +125,7 @@ module Gollum # :sanitization - An instance of Sanitization. # :page_file_dir - String the directory in which all page files reside # :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. def initialize(path, options = {}) @@ -134,6 +143,8 @@ module Gollum @repo = @access.repo @ref = options[:ref] || self.class.default_ref @sanitization = options[:sanitization] || self.class.sanitization + @ws_subs = options[:ws_subs] || + self.class.default_ws_subs @history_sanitization = options[:history_sanitization] || self.class.history_sanitization end