Class: Gitnesse::Wiki
- Inherits:
-
Object
- Object
- Gitnesse::Wiki
- Defined in:
- lib/gitnesse/wiki.rb,
lib/gitnesse/wiki/page.rb
Defined Under Namespace
Classes: Page
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
-
#add_page(filename, content) ⇒ Object
Public: Adds or updates wiki page.
-
#commit ⇒ Object
Public: Commits staged wiki changes.
-
#initialize(url, dir, opts = {clone: true}) ⇒ Wiki
constructor
Public: Clones/updates a wiki in the provided dir.
-
#push ⇒ Object
Public: Pushes new commits to remote wiki.
-
#remove_features ⇒ Object
Public: Removes pages previously placed by Gitnesse.
Constructor Details
#initialize(url, dir, opts = {clone: true}) ⇒ Wiki
Public: Clones/updates a wiki in the provided dir
url - cloneable URL for wiki repository dir - directory to clone git wiki into opts - hash of options:
clone - whether or not to clone/update local copy of remote wiki
Returns a Gitnesse::Wiki object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gitnesse/wiki.rb', line 17 def initialize(url, dir, opts={clone: true}) @url = url @dir = dir @opts = opts @config = Gitnesse::Config.instance clone_or_update unless !opts[:clone] @repo ||= Git.init(dir) @pages = @repo.status.each_with_object([]) do |s, a| if s.path =~ /\.feature\.md$/ a << Gitnesse::Wiki::Page.new("#{dir}/#{s.path}") end end @pages end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
7 8 9 |
# File 'lib/gitnesse/wiki.rb', line 7 def dir @dir end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
7 8 9 |
# File 'lib/gitnesse/wiki.rb', line 7 def pages @pages end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
7 8 9 |
# File 'lib/gitnesse/wiki.rb', line 7 def repo @repo end |
Instance Method Details
#add_page(filename, content) ⇒ Object
Public: Adds or updates wiki page
filename - filename for wiki page content - content for page
Returns a Wiki::Page
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gitnesse/wiki.rb', line 86 def add_page(filename, content) full_filename = "#{@dir}/#{filename}" if @pages.detect { |f| f.wiki_path == full_filename } page = @pages.find { |f| f.wiki_path == full_filename } else page = Gitnesse::Wiki::Page.new(full_filename) @pages << page end page.write(content) @repo.add(filename) page end |
#commit ⇒ Object
Public: Commits staged wiki changes
Returns nothing
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gitnesse/wiki.rb', line 62 def commit begin @repo.commit("Update features with Gitnesse") rescue Git::GitExecuteError => e unless e. =~ /nothing to commit/ puts " A Git error occured. The message it passed to us was:" abort e. end end end |
#push ⇒ Object
Public: Pushes new commits to remote wiki
Returns nothing
76 77 78 |
# File 'lib/gitnesse/wiki.rb', line 76 def push @repo.push end |
#remove_features ⇒ Object
Public: Removes pages previously placed by Gitnesse. This includes the feature listing pages.
Returns nothing.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitnesse/wiki.rb', line 40 def remove_features @repo.status.each do |file| if file.path =~ /^features(\.md|\ >)/ begin @repo.remove(file.path) rescue Git::GitExecuteError => e # Git spat something on git rm [file]. Likely the file doesn't # exist, or was previously removed and hasn't been committed yet. # It's likely fine. If not, we'll abort and show the end user the # error Git sent to us. unless e. =~ /did not match any files/ puts " A Git error occured. The message it passed to us was:" abort e. end end end end end |