<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="robots" content="noindex,noarchive">
	<meta name="generator" content="Nette Tester">

	<title><?php echo $title ? htmlSpecialChars("$title - ") : ''; ?>Code coverage</title>

	<style type="text/css">
	html {
		font: 16px/1.5 sans-serif;
		border-top: 4.7em solid #F4EBDB;
	}

	body {
		max-width: 990px;
		margin: -4.7em auto 0;
		background: white;
		color: #333;
	}

	h1 {
		font-size: 1.9em;
		margin: .5em 0 1.5em;
		color: #7A7772;
		text-shadow: 1px 1px 0 white;
	}

	div.code {
		font: 14px/1.2 Consolas, monospace;
		background: #FDF5CE;
		padding: .4em .7em;
		border: 1px dotted silver;
		overflow-x: auto;
		display: none;
	}

	span.line {
		color: #9F9C7F;
		font-weight: normal;
		font-style: normal;
	}

	.t {
		background: #99f999;
	}

	.u {
		background: #f9ac9e;
	}

	td {
		vertical-align: middle;
	}

	small {
		color: gray;
	}

	.number {
		text-align: right;
		width: 50px;
	}

	.bar {
		border: 1px solid #ACACAC;
		background: #e50400;
		width: 35px;
		height: 1em;
	}

	.bar div {
		background: #1A7E1E;
		height: 1em;
	}

	.light td {
		opacity: .5;
	}

	.light td * {
		color: gray;
	}

	.not-loaded td * {
		color: red;
	}
	</style>
</head>

<body>
	<h1><?php echo $title ? htmlSpecialChars("$title - ") : ''; ?>Code coverage <?php echo $totalSum ? round($coveredSum * 100 / $totalSum) : 0 ?>&nbsp;%</h1>

	<?php foreach ($files as $id => $info): ?>
	<div>
		<table>
		<tr<?php echo $info->class ? " class='$info->class'" : '' ?>>
			<td class="number"><small><?php echo $info->coverage ?> %</small></td>
			<td><div class="bar"><div style="width: <?php echo $info->coverage ?>%"></div></div></td>
			<td><a href="#fragment<?php echo $id ?>" onclick="toggle(this); return false"><span><?php echo $info->name ?></span></a></td>
		</tr>
		</table>

		<div class="code" id="fragment<?php echo $id ?>">
		<?php
			$source = explode('<br />', highlight_file($info->file, TRUE));

			end($source);
			$numWidth = strlen((string) key($source));

			unset($prevColor);
			$tags = '';
			foreach ($source as $n => $line) {
				if (isset($info->lines[$n + 1]) && isset($classes[$info->lines[$n + 1]])) {
					$color = $classes[$info->lines[$n + 1]];
				} else {
					$color = '';  // not executable
				}
				if (!isset($prevColor)) {
					$prevColor = $color;
				}
				$line = sprintf("<span class='line'>%{$numWidth}s:    </span>", $n + 1) . $line;
				if ($prevColor !== $color || $n === count($source) - 1) {
					echo '<div' . ($prevColor ? " class='$prevColor'" : '') . '>', str_replace(' />', '>', $tags);
					$openTags = array();
					preg_match_all('#<([^>]+)#', $tags, $matches);
					foreach ($matches[1] as $m) {
						if ($m[0] === '/') {
							array_pop($openTags);
						} elseif (substr($m, -1) !== '/') {
							$openTags[] = $m;
						}
					}
					foreach (array_reverse($openTags) as $tag) {
						echo '</' . preg_replace('# .*#', '', $tag) . '>';
					}
					echo "</div>\n";
					$tags = ($openTags ? '<' . implode('><', $openTags) . '>' : '');
					$prevColor = $color;
				}
				$tags .= "$line<br />\n";
			}
		?></div>
	</div>
	<?php endforeach ?>

	<footer>
		<p>Generated by <a href="https://tester.nette.org">Nette Tester</a> at <?php echo @date('Y/m/d H:i:s') // @ timezone may not be set ?></p>
	</footer>

	<script>
	function toggle(link) {
		var el = document.getElementById(link.href.split('#')[1]);
		if (el.style.display === 'block') {
			el.style.display = 'none';
			return false;
		} else {
			el.style.display = 'block';
		}
	}
	</script>
</body>
</html>
