Class: Gitnesse::Wiki::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/gitnesse/wiki/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Page

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



12
13
14
15
16
17
# File 'lib/gitnesse/wiki/page.rb', line 12

def initialize(path)
  @wiki_path = path
  @relative_path = get_relative_path
  @filename = get_filename
  @path = "#{@relative_path}/#{@filename}".gsub("//", "/")
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/gitnesse/wiki/page.rb', line 4

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/gitnesse/wiki/page.rb', line 4

def path
  @path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



4
5
6
# File 'lib/gitnesse/wiki/page.rb', line 4

def relative_path
  @relative_path
end

#wiki_pathObject (readonly)

Returns the value of attribute wiki_path.



4
5
6
# File 'lib/gitnesse/wiki/page.rb', line 4

def wiki_path
  @wiki_path
end

Instance Method Details

#append_result(scenario, status, subtitle = nil) ⇒ Object

Public: Appends the result of a Cucumber scenario to the feature’s wiki page.

scenario - feature scenario that was run status - return status of the scenario, e.g. :passed, :undefined, :failing subtitle - subtitle of scenario (used for scenario outlines)

Returns nothing



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gitnesse/wiki/page.rb', line 60

def append_result(scenario, status, subtitle = nil)
  image = "![](//s3.amazonaws.com/gitnesse/github/#{status.to_s}.png)"
  time = Time.now.strftime("%b %d, %Y, %-l:%M %p")
  identifier = Gitnesse::Config.instance.identifier

  string = "\n- #{image} **#{scenario}**".chomp
  string << "\n- **(#{subtitle})**" if subtitle
  string << "\n- #{identifier} - #{time}\n\n---"

  write(read + string)
end

#readObject

Public: Reads the file’s contents. Caches result so only reads from FS first time it’s called per page.

Returns a string



23
24
25
# File 'lib/gitnesse/wiki/page.rb', line 23

def read
  @content ||= File.read(@wiki_path)
end

#remove_resultsObject

Public: Removes existing results from the feature page.

Returns nothing



43
44
45
46
47
48
49
# File 'lib/gitnesse/wiki/page.rb', line 43

def remove_results
  content = read
  # Remove old Cucumber results, if they exist
  content.gsub!(/(\s+\!\[\].*)/, '') unless content =~ /\s+- !\[\].*---/m
  content.gsub!(/\s+- !\[\].*---/m, '')
  write content
end

#write(content) ⇒ Object

Public: Writes content to the file.

Returns the passed content



30
31
32
33
34
35
36
37
38
# File 'lib/gitnesse/wiki/page.rb', line 30

def write(content)
  File.open(@wiki_path, 'w+') do |f|
    f.write content
  end

  @content = nil

  content
end