add Page#format

This commit is contained in:
Tom Preston-Werner
2010-04-09 23:02:14 -06:00
parent badff21cc4
commit 8132f4c602
2 changed files with 29 additions and 0 deletions
+28
View File
@@ -30,6 +30,34 @@ module Gollum
self.blob.data rescue nil
end
# The format of the page.
#
# Returns the Symbol format of the page. One of:
# [ :markdown | :textile | :rdoc | :org | :rest | :asciidoc | :pod |
# :roff ]
def format
case blob.name
when /\.(md|mkdn?|mdown|markdown)$/i
:markdown
when /\.(textile)$/i
:textile
when /\.(rdoc)$/i
:rdoc
when /\.(org)$/i
:org
when /\.(re?st(\.txt)?)$/i
:rest
when /\.(asciidoc)$/i
:asciidoc
when /\.(pod)$/i
:pod
when /\.(\d)$/i
:roff
else
nil
end
end
# Find a page in the given Gollum repo.
#
# name - The human or canonical String page name to find.
+1
View File
@@ -14,6 +14,7 @@ context "Page" do
page = @wiki.formatted_page('Bilbo Baggins')
assert_equal Gollum::Page, page.class
assert page.data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
assert_equal :markdown, page.format
end
test "no page match" do