add Page#format
This commit is contained in:
@@ -30,6 +30,34 @@ module Gollum
|
|||||||
self.blob.data rescue nil
|
self.blob.data rescue nil
|
||||||
end
|
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.
|
# Find a page in the given Gollum repo.
|
||||||
#
|
#
|
||||||
# name - The human or canonical String page name to find.
|
# name - The human or canonical String page name to find.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ context "Page" do
|
|||||||
page = @wiki.formatted_page('Bilbo Baggins')
|
page = @wiki.formatted_page('Bilbo Baggins')
|
||||||
assert_equal Gollum::Page, page.class
|
assert_equal Gollum::Page, page.class
|
||||||
assert page.data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
assert page.data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||||
|
assert_equal :markdown, page.format
|
||||||
end
|
end
|
||||||
|
|
||||||
test "no page match" do
|
test "no page match" do
|
||||||
|
|||||||
Reference in New Issue
Block a user