From c37204e42af28abf63819bd5eaa71c733246e6cf Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sat, 10 Apr 2010 11:29:57 -0600 Subject: [PATCH] move formatted vs raw into Page --- README.md | 23 ++++++----------------- lib/gollum.rb | 1 + lib/gollum/page.rb | 20 +++++++++++++++++--- lib/gollum/wiki.rb | 2 +- test/test_page.rb | 14 ++++++++------ 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 5f1a34fa..eca3682d 100644 --- a/README.md +++ b/README.md @@ -230,12 +230,15 @@ Initialize the Gollum::Repo object: gollum = Gollum::Wiki.new("my-gollum-repo.git") # => -Get the latest HTML formatted version of the given canonical page name: +Get the latest version of the given human or canonical page name: - page = gollum.formatted_page('page-name') + page = gollum.page('page-name') # => - page.data + page.raw_data + # => "# My wiki page" + + page.formatted_data # => "

My wiki page

" page.format @@ -247,20 +250,6 @@ Get the latest HTML formatted version of the given canonical page name: vsn.id # => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5' -Get the latest raw version of the given canonical page name: - - gollum.raw_page('page-name') - # => - - page.data - # => "# My wiki page" - - page.format - # => :markdown - - page.version - # => - Get a list of versions for a given canonical page name: vsns = gollum.page_versions('page-name') diff --git a/lib/gollum.rb b/lib/gollum.rb index f41f00ab..c157356c 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -1,5 +1,6 @@ # external require 'grit' +require 'github/markup' # internal require 'gollum/wiki' diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index a0272c0a..330e19f5 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -23,10 +23,24 @@ module Gollum self end - # The contents of the page. + # The on-disk filename of the page. + # + # Returns the String name. + def name + self.blob.name rescue nil + end + + # The formatted contents of the page. # # Returns the String data. - def data + def formatted_data + GitHub::Markup.render(self.blob.name, self.blob.data) rescue nil + end + + # The raw contents of the page. + # + # Returns the String data. + def raw_data self.blob.data rescue nil end @@ -65,7 +79,7 @@ module Gollum # Returns a Gollum::Page or nil if the page could not be found. def find(name) commit = self.wiki.repo.commits.first - content = find_page_in_tree(commit.tree, name) + find_page_in_tree(commit.tree, name) end # private diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 24e2fa9e..df5c1643 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -17,7 +17,7 @@ module Gollum # name - The human or canonical String page name of the wiki page. # # Returns a Gollum::Page or nil if no matching page was found. - def formatted_page(name) + def page(name) Page.new(self).find(name) end end diff --git a/test/test_page.rb b/test/test_page.rb index b797628e..001bd835 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -7,21 +7,23 @@ context "Page" do test "new page" do page = Gollum::Page.new(@wiki) - assert_nil page.data + assert_nil page.raw_data + assert_nil page.formatted_data end - test "formatted page" do - page = @wiki.formatted_page('Bilbo Baggins') + test "get existing page" do + page = @wiki.page('Bilbo Baggins') assert_equal Gollum::Page, page.class - assert page.data =~ /^# Bilbo Baggins\n\nBilbo Baggins/ + assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/ + assert page.formatted_data =~ /

Bilbo Baggins<\/h1>\n\n

Bilbo Baggins/ assert_equal :markdown, page.format end test "no page match" do - assert_nil @wiki.formatted_page('I do not exist') + assert_nil @wiki.page('I do not exist') end test "no ext match" do - assert_nil @wiki.formatted_page('Data') + assert_nil @wiki.page('Data') end end \ No newline at end of file