From 8132f4c6022499c266743a08acfdb3ef84ce3cbc Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Fri, 9 Apr 2010 23:02:14 -0600 Subject: [PATCH] add Page#format --- lib/gollum/page.rb | 28 ++++++++++++++++++++++++++++ test/test_page.rb | 1 + 2 files changed, 29 insertions(+) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 602a0ca8..a0272c0a 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -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. diff --git a/test/test_page.rb b/test/test_page.rb index 07f3004e..b797628e 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -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