diff --git a/README.md b/README.md index 0f27ffce..6ae41f7b 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,8 @@ The above tag will create a link to the corresponding page file named `Frodo.ext` where `ext` may be any of the allowed extension types. The conversion is as follows: - 1. Strip any non-printables (U+0000-U+001F, U+007F-U+009F) - 2. Replace any spaces (U+0020) with dashes (U+002D) - 3. Replace any slashes (U+002F) with dashes (U+002D) + 1. Replace any spaces (U+0020) with dashes (U+002D) + 2. Replace any slashes (U+002F) with dashes (U+002D) If you'd like the link text to be something that doesn't map directly to the page name, you can specify the actual page name after a pipe: diff --git a/lib/gollum.rb b/lib/gollum.rb index 4006661e..28a67d74 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -10,17 +10,4 @@ require 'gollum/markup' module Gollum VERSION = '0.0.1' - - # Convert a human page name into a canonical page name. - # - # name - The String human page name. - # - # Examples - # Gollum.canonical_name("Bilbo Baggins") - # # => 'Bilbo-Baggins' - # - # Returns the String canonical name. - def self.canonical_name(name) - name.gsub(/ /, '-') - end end \ No newline at end of file diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index ef13e1c2..63206320 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -182,7 +182,7 @@ module Gollum def process_page_link_tag(tag) parts = tag.split('|') name = parts[0].strip - cname = Gollum::canonical_name((parts[1] || parts[0]).strip) + cname = Page.cname((parts[1] || parts[0]).strip) %{#{name}} end diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 943618f7..436ccbc6 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -84,6 +84,19 @@ module Gollum # ######################################################################### + # Convert a human page name into a canonical page name. + # + # name - The String human page name. + # + # Examples + # Page.cname("Bilbo Baggins") + # # => 'Bilbo-Baggins' + # + # Returns the String canonical name. + def self.cname(name) + name.gsub(%r{[ /]}, '-') + end + # Convert a format Symbol into an extension String. # # format - The format Symbol. @@ -195,7 +208,7 @@ module Gollum # Returns a Boolean. def page_match(name, filename) if filename =~ VALID_PAGE_RE - Gollum.canonical_name(name) == Gollum.canonical_name($1) + Page.cname(name) == Page.cname($1) else false end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 6c7cca90..7ecbca77 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -42,7 +42,7 @@ module Gollum # Returns the String SHA1 of the newly written version. def write_page(name, format, data, commit = {}) ext = Page.format_to_ext(format) - path = Gollum.canonical_name(name) + '.' + ext + path = Page.cname(name) + '.' + ext map = {} if pcommit = @repo.commit('master')