Skip to content

Commit

Permalink
First attempt at wiki wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
stewart committed Aug 12, 2013
1 parent 819c5c0 commit 7f9d8ef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gitnesse.rb
Expand Up @@ -7,6 +7,7 @@
require 'gitnesse/feature_transform'
require 'gitnesse/git_config_reader'
require 'gitnesse/dir_manager'
require 'gitnesse/wiki'

module Gitnesse
end
25 changes: 25 additions & 0 deletions lib/gitnesse/wiki.rb
@@ -0,0 +1,25 @@
Dir[File.dirname(__FILE__) + "/wiki/*.rb"].each { |f| require(f) }

require 'grit'

module Gitnesse
class Wiki
attr_reader :repo, :pages

# Public: Clones a wiki into the provided dir
#
# repository_url - cloneable URL for wiki repository
# dir - directory to clone git wiki into
#
# Returns a Gitnesse::Wiki object
def initialize(repository_url, dir)
`git clone #{repository_url} #{dir} &> /dev/null`
@repo = Grit::Repo.new dir
@pages = @repo.status.map do |s|
Gitnesse::Wiki::Page.new("#{dir}/#{s.path}") if s.path =~ /\.md$/
end

@pages
end
end
end
19 changes: 19 additions & 0 deletions lib/gitnesse/wiki/page.rb
@@ -0,0 +1,19 @@
module Gitnesse
class Wiki
class Page
attr_reader :name, :filename, :path

# Public: Creates a new Wiki Page object. Contains references to the page
# and an easy way to access/update relevant page data.
#
# path - full path to the file
#
# Returns a Wiki::Page object
def initialize(path)
@path = path
@filename = File.basename path
@name = File.basename path, ".md"
end
end
end
end
13 changes: 13 additions & 0 deletions spec/lib/wiki/page_spec.rb
@@ -0,0 +1,13 @@
require 'spec_helper'

module Gitnesse
describe Wiki::Page do
let(:page) { Wiki::Page.new("~/.gitnesse/gitnesse/new_feature.md") }

it "takes a path and splits it into filename and name" do
expect(page.name).to eq "new_feature"
expect(page.filename).to eq "new_feature.md"
expect(page.path).to eq "~/.gitnesse/gitnesse/new_feature.md"
end
end
end

0 comments on commit 7f9d8ef

Please sign in to comment.