From 9307900b09e101e35ef3f2c28482518a5585d9c3 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 11 Apr 2010 12:53:03 -0600 Subject: [PATCH] add Gollum::File --- README.md | 8 ++++---- lib/gollum.rb | 1 + lib/gollum/file.rb | 14 ++++++++++++++ lib/gollum/wiki.rb | 9 +++++++++ test/test_file.rb | 11 +++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 lib/gollum/file.rb create mode 100644 test/test_file.rb diff --git a/README.md b/README.md index b187dde2..9e9a60c2 100644 --- a/README.md +++ b/README.md @@ -267,18 +267,18 @@ Get a specific version of a given canonical page file: Get the latest version of a given static file: - file = gollum.static_file('asset.js') + file = gollum.file('asset.js') # => - file.data + file.raw_data # => "alert('hello');" file.version - # => + # => Get a specific version of a given static file: - gollum.static_file('asset.js', '5ec521178e0eec4dc39741a8978a2ba6616d0f0a') + gollum.file('asset.js', '5ec521178e0eec4dc39741a8978a2ba6616d0f0a') Write a new version of a given canonical page file (the file will be created if it does not already exist) and commit the change. diff --git a/lib/gollum.rb b/lib/gollum.rb index c157356c..6949c8f6 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -5,6 +5,7 @@ require 'github/markup' # internal require 'gollum/wiki' require 'gollum/page' +require 'gollum/file' module Gollum VERSION = '0.0.1' diff --git a/lib/gollum/file.rb b/lib/gollum/file.rb new file mode 100644 index 00000000..da244d63 --- /dev/null +++ b/lib/gollum/file.rb @@ -0,0 +1,14 @@ +module Gollum + class File + attr_accessor :wiki + + # Initialize a file. + # + # wiki - The Gollum::Wiki in question. + # + # Returns a newly initialized Gollum::File. + def initialize(wiki) + self.wiki = wiki + end + end +end \ No newline at end of file diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index c93b22e2..b13e6cb2 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -21,5 +21,14 @@ module Gollum def page(name, version = 'master') Page.new(self).find(name, version) end + + # Get the static file for a given name. + # + # name - The full String pathname to the file. + # + # Returns a Gollum::File or nil if no matching file was found. + def file(name) + File.new(self).find(name) + end end end \ No newline at end of file diff --git a/test/test_file.rb b/test/test_file.rb new file mode 100644 index 00000000..47b9c97a --- /dev/null +++ b/test/test_file.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), *%w[helper]) + +context "File" do + setup do + @wiki = Gollum::Wiki.new(testpath("examples/lotr.git")) + end + + test "new file" do + file = Gollum::File.new(@wiki) + end +end \ No newline at end of file