Gollum.canonical_name -> Page.cname

This commit is contained in:
Tom Preston-Werner
2010-04-19 17:07:10 -07:00
parent addf3bb721
commit 0b848d720c
5 changed files with 18 additions and 19 deletions
+2 -3
View File
@@ -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:
-13
View File
@@ -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
+1 -1
View File
@@ -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)
%{<a href="#{cname}">#{name}</a>}
end
+14 -1
View File
@@ -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
+1 -1
View File
@@ -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')