Class: ConfluenceStepOutputter

Inherits:
Object
  • Object
show all
Defined in:
lib/confluence_step_outputter.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ConfluenceStepOutputter

Returns a new instance of ConfluenceStepOutputter.



7
8
9
10
# File 'lib/confluence_step_outputter.rb', line 7

def initialize(file)
  @file = File.open(file, 'w')
  @previous_type = ""
end

Instance Method Details

#closeObject



20
21
22
# File 'lib/confluence_step_outputter.rb', line 20

def close
  @file.close
end

#end_allObject



40
41
42
# File 'lib/confluence_step_outputter.rb', line 40

def end_all
  # No-op
end

#end_directoryObject



30
31
32
# File 'lib/confluence_step_outputter.rb', line 30

def end_directory
  # No-op
end

No-op



15
16
17
18
# File 'lib/confluence_step_outputter.rb', line 15

def footer
  @file.puts %(<p>&nbsp;</p>)
  @file.puts %(<p><em>Documentation generated #{Time.now}</em></p>)
end

#headerObject



12
13
14
# File 'lib/confluence_step_outputter.rb', line 12

def header
  # No-op
end

#start_allObject



34
35
36
37
38
# File 'lib/confluence_step_outputter.rb', line 34

def start_all
  @file.puts %(<p>&nbsp;</p>)
  @file.puts "<h2>All definitions alphabetically</h2>"
  @previous_type = ""
end

#start_directory(dir) ⇒ Object



24
25
26
27
28
# File 'lib/confluence_step_outputter.rb', line 24

def start_directory(dir)
  @file.puts %(<p>&nbsp;</p>)
  @file.puts "<h2>#{dir}</h2>"
  @previous_type = ""
end

#step(step) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/confluence_step_outputter.rb', line 44

def step(step)
  if @previous_type != step[:type]
    @file.puts %(<h3>#{step[:type]} definitions</h3>)
    @previous_type = step[:type]
  end
  @file.puts %(<ac:macro ac:name="expand">)
  @file.puts %( <ac:parameter ac:name="title">#{CGI.escapeHTML(step[:name])}</ac:parameter>)
  @file.puts %( <ac:rich-text-body>)
  # TODO: Add link to source repo or Jenkins workspace
  # <p><a href=".../#{CGI.escapeHTML(step[:filename])}" style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</a></p>
  @file.puts %(  <p style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</p>)
  @file.puts %(  <pre style="background-color: #ddd; padding-top: 1.2em;">)
  step[:code].each do |line|
    @file.puts %(   #{CGI.escapeHTML(line)})
  end
  @file.puts %(  </pre>)
  @file.puts %( </ac:rich-text-body>)
  @file.puts %(</ac:macro>)
end