Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |