Gollum.canonical_name -> Page.cname
This commit is contained in:
@@ -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
|
`Frodo.ext` where `ext` may be any of the allowed extension types. The
|
||||||
conversion is as follows:
|
conversion is as follows:
|
||||||
|
|
||||||
1. Strip any non-printables (U+0000-U+001F, U+007F-U+009F)
|
1. Replace any spaces (U+0020) with dashes (U+002D)
|
||||||
2. Replace any spaces (U+0020) with dashes (U+002D)
|
2. Replace any slashes (U+002F) with dashes (U+002D)
|
||||||
3. 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
|
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:
|
page name, you can specify the actual page name after a pipe:
|
||||||
|
|||||||
@@ -10,17 +10,4 @@ require 'gollum/markup'
|
|||||||
|
|
||||||
module Gollum
|
module Gollum
|
||||||
VERSION = '0.0.1'
|
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
|
end
|
||||||
@@ -182,7 +182,7 @@ module Gollum
|
|||||||
def process_page_link_tag(tag)
|
def process_page_link_tag(tag)
|
||||||
parts = tag.split('|')
|
parts = tag.split('|')
|
||||||
name = parts[0].strip
|
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>}
|
%{<a href="#{cname}">#{name}</a>}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -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.
|
# Convert a format Symbol into an extension String.
|
||||||
#
|
#
|
||||||
# format - The format Symbol.
|
# format - The format Symbol.
|
||||||
@@ -195,7 +208,7 @@ module Gollum
|
|||||||
# Returns a Boolean.
|
# Returns a Boolean.
|
||||||
def page_match(name, filename)
|
def page_match(name, filename)
|
||||||
if filename =~ VALID_PAGE_RE
|
if filename =~ VALID_PAGE_RE
|
||||||
Gollum.canonical_name(name) == Gollum.canonical_name($1)
|
Page.cname(name) == Page.cname($1)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ module Gollum
|
|||||||
# Returns the String SHA1 of the newly written version.
|
# Returns the String SHA1 of the newly written version.
|
||||||
def write_page(name, format, data, commit = {})
|
def write_page(name, format, data, commit = {})
|
||||||
ext = Page.format_to_ext(format)
|
ext = Page.format_to_ext(format)
|
||||||
path = Gollum.canonical_name(name) + '.' + ext
|
path = Page.cname(name) + '.' + ext
|
||||||
|
|
||||||
map = {}
|
map = {}
|
||||||
if pcommit = @repo.commit('master')
|
if pcommit = @repo.commit('master')
|
||||||
|
|||||||
Reference in New Issue
Block a user