r19cov 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+ require 'erb'
6
+ require 'cgi'
7
+
8
+ module R19Cov
9
+ module Report
10
+ class HTML
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ attr_reader :options
16
+
17
+ def output_dir
18
+ options.output_dir
19
+ end
20
+
21
+ def output(coverages)
22
+ create_output_dir
23
+ copy_stylesheet
24
+ summary = R19Cov::Coverage::Summary.new(coverages)
25
+ page = IndexPage.new(summary, options)
26
+ page.output
27
+ coverages.each do |coverage|
28
+ page = DetailPage.new(coverage, options)
29
+ page.output
30
+ end
31
+ end
32
+
33
+ private
34
+ def copy_stylesheet
35
+ FileUtils.cp(File.join(File.dirname(__FILE__), 'html', 'templates', 'r19cov.css'),
36
+ output_dir)
37
+ end
38
+
39
+ def create_output_dir
40
+ FileUtils.rm_r(output_dir) if remove?
41
+ Dir.mkdir(output_dir) unless File.exist?(output_dir)
42
+ end
43
+
44
+ def remove?
45
+ File.exist?(output_dir)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module R19Cov
4
+ module Report
5
+ class HTML
6
+ class DetailPage
7
+ include Page
8
+
9
+ def initialize(coverage, options)
10
+ @coverage = coverage
11
+ @options = options
12
+ end
13
+
14
+ attr_accessor :coverage, :options
15
+
16
+ def output
17
+ File.open(html_file(@coverage.filename), 'w') do |file|
18
+ file.puts html('detail')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module R19Cov
4
+ module Report
5
+ class HTML
6
+ class IndexPage
7
+ include Page
8
+
9
+ def initialize(summary, options)
10
+ @summary = summary
11
+ @options = options
12
+ end
13
+
14
+ attr_reader :summary, :options
15
+
16
+ def output
17
+ File.open(html_file(@summary.filename), 'w') do |file|
18
+ file.puts html('index')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,93 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module R19Cov
4
+ module Report
5
+ class HTML
6
+ module Page
7
+ PERCENTAGE_RATE = 100.0
8
+ PERCENTAGE_FORMAT_DIGIT = 2
9
+ MAX_FILENAME_SIZE = 70
10
+
11
+ def html_path(filename)
12
+ Pathname.new(filename).cleanpath.to_s.gsub(%r|^\w:[/\\]|, '').gsub(/\./, '_').\
13
+ gsub(%r|[\\\/]|, '-') + ".html"
14
+ end
15
+
16
+ def html(page)
17
+ ERB.new(template(page)).result(get_binding)
18
+ end
19
+
20
+ def html_file(filename)
21
+ File.join(output_dir, html_path(filename))
22
+ end
23
+
24
+ def targets
25
+ options.targets.join(', ')
26
+ end
27
+
28
+ def raw_options
29
+ options.raw_options.join(' ')
30
+ end
31
+
32
+ def output_dir
33
+ options.output_dir
34
+ end
35
+
36
+ def template(page)
37
+ template_file = File.join(File.dirname(__FILE__), 'templates', "#{page}.html.erb")
38
+ File.read(template_file)
39
+ end
40
+
41
+ def filename_format(filename)
42
+ current_dir = Dir.pwd
43
+ filename = filename.sub(%r|^#{current_dir}|, '.')
44
+
45
+ if filename.size > MAX_FILENAME_SIZE
46
+ "..." + filename[filename.size - MAX_FILENAME_SIZE .. -1]
47
+ else
48
+ filename
49
+ end
50
+ end
51
+
52
+ def line_format(line)
53
+ line = ' ' if line == ''
54
+ CGI::escapeHTML(line)
55
+ end
56
+
57
+ def get_binding
58
+ binding
59
+ end
60
+
61
+ def generated_on
62
+ Time.now
63
+ end
64
+
65
+ def percentage_bar(rate)
66
+ rate = rate * PERCENTAGE_RATE
67
+ <<-HTML
68
+ <div class="percentage_bar">
69
+ <div class="covered" style="width:#{rate.to_i}px;"></div>
70
+ <div class="uncovered" style="width:#{100 - rate.to_i}px;"></div>
71
+ </div>
72
+ HTML
73
+ end
74
+
75
+ def percentage_format(value)
76
+ value = ((value * (10 ** PERCENTAGE_FORMAT_DIGIT) * PERCENTAGE_RATE)).ceil.to_f /
77
+ (10 ** PERCENTAGE_FORMAT_DIGIT).to_f
78
+ "#{value}%"
79
+ end
80
+
81
+ def coverage_class(coverage)
82
+ if coverage.nil?
83
+ "non"
84
+ elsif coverage >= 1
85
+ "covered"
86
+ elsif coverage == 0
87
+ "uncovered"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,75 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title><%= coverage.filename %></title>
5
+ <link href="r19cov.css" media="all" rel="stylesheet" type="text/css" />
6
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
7
+ </head>
8
+ <body>
9
+ <h1>Coverage Report - R19Cov</h1>
10
+
11
+ <div class="component">
12
+ <h2>Information</h2>
13
+ <table class="information">
14
+ <tbody>
15
+ <tr>
16
+ <th>filename</th>
17
+ <td><%= coverage.filename %></td>
18
+ </tr>
19
+ <tr>
20
+ <th>generated on</th>
21
+ <td><%= generated_on %></td>
22
+ </tr>
23
+ </tbody>
24
+ </table>
25
+ </div>
26
+
27
+ <div class="component">
28
+ <h2>Coverage</h2>
29
+ <table class="report">
30
+ <thead>
31
+ <tr>
32
+ <th class="left_align">Total Lines</th>
33
+ <th class="left_align">Lines of Code</th>
34
+ <th class="left_align" colspan="2">Total Coverage</th>
35
+ <th class="left_align" colspan="2">Code Coverage</th>
36
+ </tr>
37
+ </thead>
38
+ <tbody>
39
+ <tr>
40
+ <td class="left_align"><%= coverage.total_lines %></td>
41
+ <td class="left_align"><%= coverage.lines_of_code %></td>
42
+ <td class="left_align"><%= percentage_bar(coverage.total_coverage) %></td>
43
+ <td class="left_align"><%= percentage_format(coverage.total_coverage) %></td>
44
+ <td class="left_align"><%= percentage_bar(coverage.code_coverage) %></td>
45
+ <td class="left_align"><%= percentage_format(coverage.code_coverage) %></td>
46
+ </tr>
47
+ </tbody>
48
+ <tfoot>
49
+ <tr>
50
+ <td colspan="6"></td>
51
+ </tr>
52
+ </tfoot>
53
+ </table>
54
+ </div>
55
+
56
+ <div class="component">
57
+ <h2>Details</h2>
58
+ <table class="detail">
59
+ <tbody>
60
+ <% coverage.total_lines.times do |i| %>
61
+ <tr class="<%= coverage_class(coverage.result[i]) %>">
62
+ <td class="line_number"><%= i + 1 %></td>
63
+ <!--
64
+ <td><%= coverage.result[i] %></td>
65
+ -->
66
+ <td class-"code">
67
+ <pre><%= line_format(coverage.lines[i]) %></pre>
68
+ </td>
69
+ </tr>
70
+ <% end %>
71
+ </tbody>
72
+ </table>
73
+ </div>
74
+ </body>
75
+ </html>
@@ -0,0 +1,99 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title><%= summary.filename %></title>
5
+ <link href="r19cov.css" media="all" rel="stylesheet" type="text/css" />
6
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
7
+ </head>
8
+ <body>
9
+ <h1>Coverage Report - R19Cov</h1>
10
+
11
+ <div class="component">
12
+ <h2>Information</h2>
13
+ <table class="information">
14
+ <tbody>
15
+ <tr>
16
+ <th>target files</th>
17
+ <td><%= targets %></td>
18
+ </tr>
19
+ <tr>
20
+ <th>options</th>
21
+ <td><%= raw_options %></td>
22
+ </tr>
23
+ <tr>
24
+ <th>generated on</th>
25
+ <td><%= generated_on %></td>
26
+ </tr>
27
+ </tbody>
28
+ </table>
29
+ </div>
30
+
31
+ <div class="component">
32
+ <h2>Summary</h2>
33
+ <table class="report">
34
+ <thead>
35
+ <tr>
36
+ <th class="left_align">Total Lines</th>
37
+ <th class="left_align">Lines of Code</th>
38
+ <th class="left_align" colspan="2">Total Coverage</th>
39
+ <th class="left_align" colspan="2">Code Coverage</th>
40
+ </tr>
41
+ </thead>
42
+ <tbody>
43
+ <tr>
44
+ <td class="left_align"><%= summary.total_lines %></td>
45
+ <td class="left_align"><%= summary.lines_of_code %></td>
46
+ <td class="left_align"><%= percentage_bar(summary.total_coverage) %></td>
47
+ <td class="left_align"><%= percentage_format(summary.total_coverage) %></td>
48
+ <td class="left_align"><%= percentage_bar(summary.code_coverage) %></td>
49
+ <td class="left_align"><%= percentage_format(summary.code_coverage) %></td>
50
+ </tr>
51
+ </tbody>
52
+ <tfoot>
53
+ <tr>
54
+ <td colspan="6"></td>
55
+ </tr>
56
+ </tfoot>
57
+ </table>
58
+ </div>
59
+
60
+ <div class="component">
61
+ <h2>Details</h2>
62
+ <table class="report">
63
+ <thead>
64
+ <tr>
65
+ <th class="left_align">Filename</th>
66
+ <th class="left_align">Total Lines</th>
67
+ <th class="left_align">Lines of Code</th>
68
+ <th class="left_align">Lines of Covered</th>
69
+ <th class="left_align" colspan="2">Total Coverage</th>
70
+ <th class="left_align" colspan="2">Code Coverage</th>
71
+ </tr>
72
+ </thead>
73
+ <tbody>
74
+ <% summary.coverages.each do |coverage| %>
75
+ <tr>
76
+ <td class="left_align">
77
+ <a href="<%= html_path(coverage.filename) %>">
78
+ <%= filename_format(coverage.filename) %>
79
+ </a>
80
+ </td>
81
+ <td class="right_align"><%= coverage.total_lines %></td>
82
+ <td class="right_align"><%= coverage.lines_of_code %></td
83
+ <td class="right_align"><%= coverage.covered %></td
84
+ <td class="left_align"><%= percentage_bar(coverage.total_coverage) %></td>
85
+ <td class="left_align"><%= percentage_format(coverage.total_coverage) %></td>
86
+ <td class="left_align"><%= percentage_bar(coverage.code_coverage) %></td>
87
+ <td class="left_align"><%= percentage_format(coverage.code_coverage) %></td>
88
+ </tr>
89
+ <% end %>
90
+ </tbody>
91
+ <tfoot>
92
+ <tr>
93
+ <td colspan="8"></td>
94
+ </tr>
95
+ </tfoot>
96
+ </table>
97
+ </div>
98
+ </body>
99
+ </html>
@@ -0,0 +1,225 @@
1
+ /* General */
2
+ body {
3
+ font-family: Verdana, Helvetica, Arial, Sans-Serif;
4
+ font-size: 12px;
5
+ color: #1C1C1C;
6
+ background-color: #F4F2ED;
7
+ padding: 1em;
8
+ }
9
+
10
+ a:link {
11
+ color: #191919;
12
+ }
13
+
14
+ a:visited {
15
+ color: #191919;
16
+ }
17
+
18
+ pre, code {
19
+ color: #000000;
20
+ font-family: "Bitstream Vera Sans Mono","Monaco","Courier New",monospace;
21
+ font-size: 95%;
22
+ line-height: 1.3em;
23
+ margin-top: 0;
24
+ margin-bottom: 0;
25
+ padding: 0;
26
+ word-wrap: break-word;
27
+ }
28
+
29
+ h1, h2, h3, h4, h5, h6 {
30
+ margin: 0em 0em 1em 0em;
31
+ color: #444444;
32
+ }
33
+
34
+ h1 {
35
+ display: block;
36
+ font-size: 2em;
37
+ letter-spacing: -1px;
38
+ }
39
+
40
+ h2 {
41
+ margin-top: -1em;
42
+ }
43
+
44
+ fieldset {
45
+ display: inline;
46
+ border: 0px;
47
+ padding: 0px;
48
+ margin-right: 1em;
49
+ }
50
+
51
+ div.filters {
52
+ margin-bottom: 1em;
53
+ }
54
+
55
+ .hidden {
56
+ display: none;
57
+ }
58
+ /* end of General */
59
+
60
+
61
+ /* Component */
62
+ div.component {
63
+ padding-bottom: 1em;
64
+ width: 100%;
65
+ margin-bottom: 1em;
66
+ }
67
+ /* end of Component */
68
+
69
+ /* Information */
70
+ table.information {
71
+ border-collapse: collapse;
72
+ border: 1px solid #444444;
73
+ width: 100%;
74
+ margin-bottom: 1em;
75
+ padding-bottom: 1em;
76
+ }
77
+
78
+ table.information tr {
79
+ background-color: #eeeeee;
80
+ }
81
+
82
+ table.information th {
83
+ background: #444444;
84
+ color: #ffffff;
85
+ text-align: left;
86
+ text-transform: uppercase;
87
+ font-size: .8em;
88
+ font-weight: bold;
89
+ padding: 0em .5em;
90
+ border: 1px solid #444444;
91
+ width: 120px;
92
+ }
93
+
94
+ table.information td {
95
+ padding: .2em .5em .2em .5em;
96
+ }
97
+
98
+ table.information tbody tr:hover {
99
+ background: #cccccc !important;
100
+ }
101
+ /* end of Information */
102
+
103
+
104
+ /* Report Table */
105
+ table.report {
106
+ border-collapse: collapse;
107
+ border: 1px solid #444444;
108
+ width: 100%;
109
+ margin-bottom: 1em;
110
+ padding-bottom: 1em;
111
+ }
112
+
113
+ table.report tr {
114
+ line-height: 1.75em;
115
+ }
116
+
117
+ table.report th {
118
+ background: #444444;
119
+ color: #ffffff;
120
+ text-align: right;
121
+ text-transform: uppercase;
122
+ font-size: .8em;
123
+ font-weight: bold;
124
+ padding: 0em .5em;
125
+ border: 1px solid #444444;
126
+ }
127
+
128
+ th.left_align, td.left_align {
129
+ text-align: left !important;
130
+ }
131
+
132
+ th.right_align, td.right_align {
133
+ text-align: right;
134
+ padding-right: 2em !important;
135
+ }
136
+
137
+ table.report td {
138
+ padding: .2em .5em .2em .5em;
139
+ }
140
+
141
+ table.report td a {
142
+ text-decoration: none;
143
+ }
144
+
145
+ table.report tbody tr:hover {
146
+ background: #cccccc !important;
147
+ }
148
+
149
+ table.report tr {
150
+ background-color: #eeeeee;
151
+ }
152
+
153
+ table.report tfoot {
154
+ border-bottom: 1px solid #444444;
155
+ }
156
+
157
+ table.report tfoot tr {
158
+ height: 0;
159
+ line-height: 0;
160
+ }
161
+ /* end of Report Table */
162
+
163
+
164
+ /* Percentage bar */
165
+ div.percentage_bar {
166
+ height: 1em;
167
+ border: #333333 1px solid;
168
+ empty-cells: show;
169
+ padding: 0px;
170
+ border-collapse: collapse;
171
+ width: 100px !important;
172
+ float: left;
173
+ margin: .5em 1em .5em 0em;
174
+ }
175
+
176
+ div.percentage_bar div {
177
+ float: left;
178
+ height: 1em;
179
+ padding: 0px !important;
180
+ }
181
+
182
+ div.percentage_bar div.covered {
183
+ /* background-color: #649632; */
184
+ background-color: #66cc33;
185
+ }
186
+
187
+ div.percentage_bar div.uncovered {
188
+ /* background-color: #a92730; */
189
+ background-color: #cc0033
190
+ }
191
+ /* end of Percentage bar */
192
+
193
+
194
+ /* Detail Table */
195
+ table.detail {
196
+ border-collapse: collapse;
197
+ border: 1px solid #444444;
198
+ width: 100%;
199
+ margin-bottom: 1em;
200
+ padding-bottom: 1em;
201
+ }
202
+
203
+ table.detail td {
204
+ padding: .25em;
205
+ }
206
+
207
+ table.detail td.line_number {
208
+ width: 30px;
209
+ text-align: right;
210
+ }
211
+
212
+ table.detail td.code {
213
+ padding-left: 1em;
214
+ }
215
+
216
+ table.detail tr.covered {
217
+ /* background-color: #bed2be; */
218
+ background-color: #9ec29e;
219
+ }
220
+
221
+ table.detail tr.uncovered {
222
+ /* background-color: #ce8b8c; */
223
+ background-color: #be7b7c;
224
+ }
225
+ /* end of Detail Table */