-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconfluence_step_outputter.rb
64 lines (54 loc) · 1.59 KB
/
confluence_step_outputter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Outputter that generates Confluence markup
require 'cgi'
require 'fileutils'
class ConfluenceStepOutputter
def initialize(file)
@file = File.open(file, 'w')
@previous_type = ""
end
def header
# No-op
end
def footer
@file.puts %(<p> </p>)
@file.puts %(<p><em>Documentation generated #{Time.now}</em></p>)
end
def close
@file.close
end
def start_directory(dir)
@file.puts %(<p> </p>)
@file.puts "<h2>#{dir}</h2>"
@previous_type = ""
end
def end_directory
# No-op
end
def start_all
@file.puts %(<p> </p>)
@file.puts "<h2>All definitions alphabetically</h2>"
@previous_type = ""
end
def end_all
# No-op
end
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
end