lib/gollum/page.rb in gollum-1.3.1 vs lib/gollum/page.rb in gollum-1.4.2
- old
+ new
@@ -74,17 +74,26 @@
nil
end
end
# Reusable filter to turn a filename (without path) into a canonical name.
- # Strips extension, converts spaces to dashes.
+ # Strips extension, converts dashes to spaces.
#
# Returns the filtered String.
def self.canonicalize_filename(filename)
- filename.split('.')[0..-2].join('.').gsub('-', ' ')
+ strip_filename(filename).gsub('-', ' ')
end
+ # Reusable filter to strip extension and path from filename
+ #
+ # filename - The string path or filename to strip
+ #
+ # Returns the stripped String.
+ def self.strip_filename(filename)
+ ::File.basename(filename, ::File.extname(filename))
+ end
+
# Public: Initialize a page.
#
# wiki - The Gollum::Wiki in question.
#
# Returns a newly initialized Gollum::Page.
@@ -98,10 +107,17 @@
# Returns the String name.
def filename
@blob && @blob.name
end
+ # Public: The on-disk filename of the page with extension stripped.
+ #
+ # Returns the String name.
+ def filename_stripped
+ self.class.strip_filename(filename)
+ end
+
# Public: The canonical page name without extension, and dashes converted
# to spaces.
#
# Returns the String name.
def name
@@ -164,13 +180,15 @@
end
end
# Public: The formatted contents of the page.
#
+ # encoding - Encoding Constant or String.
+ #
# Returns the String data.
- def formatted_data(&block)
- @blob && @wiki.markup_classes[format].new(self).render(historical?, &block)
+ def formatted_data(encoding = nil, &block)
+ @blob && markup_class.render(historical?, encoding, &block)
end
# Public: The format of the page.
#
# Returns the Symbol format of the page. One of:
@@ -178,10 +196,17 @@
# :roff ]
def format
self.class.format_for(@blob.name)
end
+ # Gets the Gollum::Markup instance that will render this page's content.
+ #
+ # Returns a Gollum::Markup instance.
+ def markup_class
+ @markup_class ||= @wiki.markup_classes[format].new(self)
+ end
+
# Public: The current version of the page.
#
# Returns the Grit::Commit.
attr_reader :version
@@ -235,21 +260,26 @@
#
#########################################################################
# 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
# Convert a format Symbol into an extension String.
#
@@ -359,22 +389,24 @@
# filename - the String filename on disk (including extension).
#
# 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
# an underscore to distinguish them from other Pages.
#
# name - String page name.
#
# Returns the Page or nil if none exists.
def find_sub_page(name)
+ return nil unless self.version
return nil if self.filename =~ /^_/
name = "_#{name.to_s.capitalize}"
return nil if page_match(name, self.filename)
dirs = self.path.split('/')