Class: HowIs::HtmlReport
Overview
HTML Report implementation
Constant Summary
collapse
- ROW_HTML_GRAPH =
<<-EOF
<tr>
<td style="width: %{label_width}">%{label_text}</td>
<td><span class="fill" style="width: %{percentage}%%">%{link_text}</span></td>
</tr>
EOF
- HTML_DOC_TEMPLATE =
<<~EOF
<!DOCTYPE html>
<html>
<head>
<title>%{title}</title>
<style>
body { font: sans-serif; }
main {
max-width: 600px;
max-width: 72ch;
margin: auto;
}
.horizontal-bar-graph {
position: relative;
width: 100%;
}
.horizontal-bar-graph .fill {
display: inline-block;
background: #CCC;
}
</style>
</head>
<body>
<main>
%{report}
</main>
</body>
</html>
EOF
Instance Attribute Summary
Attributes inherited from BaseReport
#analysis
Instance Method Summary
collapse
Methods inherited from BaseReport
#generate_report_text!, #to_h, #to_json
Instance Method Details
#export ⇒ Object
68
69
70
71
|
# File 'lib/how_is/report/html.rb', line 68
def export
@r = ""
generate_report_text!
end
|
#export_file(file) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/how_is/report/html.rb', line 103
def export_file(file)
content = Kernel.format(HTML_DOC_TEMPLATE, title: @title, report: export)
File.open(file, "w") do |f|
f.puts content
end
end
|
9
10
11
|
# File 'lib/how_is/report/html.rb', line 9
def format
:html
end
|
18
19
20
|
# File 'lib/how_is/report/html.rb', line 18
def (content)
@r += "\n<h2>#{content}</h2>\n"
end
|
#horizontal_bar_graph(data) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/how_is/report/html.rb', line 46
def horizontal_bar_graph(data)
if data.length == 1 && data[0][0] == "(No label)"
text "There are no open issues to graph."
return
end
biggest = data.map { |x| x[1] }.max
get_percentage = ->(number_of_issues) { number_of_issues * 100 / biggest }
longest_label_length = data.map(&:first).map(&:length).max
label_width = "#{longest_label_length}ch"
@r += "<table class=\"horizontal-bar-graph\">\n"
data.each do |row|
@r += Kernel.format(ROW_HTML_GRAPH, label_width: label_width,
label_text: label_text_for(row),
percentage: get_percentage.call(row[1]),
link_text: row[1])
end
@r += "</table>\n"
end
|
#link(content, url) ⇒ Object
22
23
24
|
# File 'lib/how_is/report/html.rb', line 22
def link(content, url)
%[<a href="#{url}">#{content}</a>]
end
|
#text(content) ⇒ Object
26
27
28
|
# File 'lib/how_is/report/html.rb', line 26
def text(content)
@r += "<p>#{content}</p>\n"
end
|
#title(content) ⇒ Object
13
14
15
16
|
# File 'lib/how_is/report/html.rb', line 13
def title(content)
@title = content
@r += "\n<h1>#{content}</h1>\n"
end
|
#unordered_list(arr) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/how_is/report/html.rb', line 30
def unordered_list(arr)
@r += "\n<ul>\n"
arr.each do |item|
@r += " <li>#{item}</li>\n"
end
@r += "</ul>\n\n"
end
|