Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 7290453

Browse files
committed
Added totals to index pages
1 parent a34c7b7 commit 7290453

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/HTMLReport.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public function generateIndexFile (ContextInterface $path)
139139
$files = [];
140140
$dirs = [];
141141

142+
$dir_testable = 0;
143+
$dir_total = 0;
144+
142145
foreach ($path->getChildren() as $child)
143146
{
144147
$filename = $child->getName();
@@ -155,6 +158,9 @@ public function generateIndexFile (ContextInterface $path)
155158
'label' => $numbers['total'] ? $this->getCssClass($percent) : ''
156159
];
157160

161+
$dir_testable += $numbers['testable'];
162+
$dir_total += $numbers['total'];
163+
158164
if ($child instanceof DirectoryContext)
159165
{
160166
$dirs[] = $node;
@@ -165,20 +171,24 @@ public function generateIndexFile (ContextInterface $path)
165171
}
166172
}
167173

174+
$dir_percent = $dir_total > 0 ? ($dir_testable / $dir_total) : 1;
175+
168176
// render
169177
$view = new Mustache_Engine ([
170178
'loader' => new Mustache_Loader_FilesystemLoader (__DIR__.'/views'),
171179
]);
172180

173181
$relPath = $this->convertPathToRelative ($path->getName());
174182

175-
176183
$output = $view->render ('dir', [
177-
'currentPath' => $relPath,
178-
'files' => $files,
179-
'dirs' => $dirs,
180-
'date' => date('r'),
181-
'isBaseDir' => ($this->baseDir === $path->getName())
184+
'currentPath' => $relPath,
185+
'files' => $files,
186+
'dirs' => $dirs,
187+
'date' => date('r'),
188+
'total_percent' => number_format ($dir_percent*100, 2),
189+
'total_testable' => $dir_testable,
190+
'total_total' => $dir_total,
191+
'isBaseDir' => ($this->baseDir === $path->getName())
182192
]);
183193

184194
$this->saveFile ($relPath.'/index.html', $output);

src/views/dir.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
</tr>
5252
{{/files}}
5353

54+
<tr>
55+
<td>Total</td>
56+
<td class="text-center">{{total_percent}}%</td>
57+
<td class="text-center">{{total_testable}} / {{total_total}}</td>
58+
</tr>
59+
5460
</tbody>
5561
</table>
5662

src/views/partials/header.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
5-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
4+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
5+
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"-->
6+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
7+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
8+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
9+
<!--script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0.js/bootstrap.min.js"></script-->
610
<style type="text/css">
711
.codeline { font-family: monospace; white-space: pre; }
812
</style>

0 commit comments

Comments
 (0)