Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F49451168
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
index 9ea458e..a722205 100644
--- a/src/Output/HTMLOutput.php
+++ b/src/Output/HTMLOutput.php
@@ -1,11 +1,64 @@
<?php
namespace Keruald\Reporting\Output;
class HTMLOutput extends Output {
- public function render () : string {
- return "";
+ private function makeId ($name) : string {
+ return urlencode(strtolower(str_replace(' ', '-', $name)));
+ }
+
+ private static function encode (string $text) : string {
+ return htmlspecialchars($text);
}
+ public function render () : string {
+
+ $send = [];
+ $title = $this->report->title;
+ $send[] =
+ '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
+ . '</h1>';
+
+ foreach ($this->report->sections as $section) {
+ $title = $section->title;
+ $send[] =
+ '<h2 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h2>';
+ foreach ($section->entries as $entry) {
+ $title = $entry->title;
+ $send[] = '<h3 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h3>';
+
+ $text = explode("\n\n", $entry->text);
+
+ foreach ($text as $value) {
+ $send[] = '<p>' . self::encode($value) . '</p>';
+ }
+ }
+ }
+ $send[] = '<hr>';
+
+ $send[] = '<h2 id="report-properties">Report properties</h2>';
+ $send[] = '<table>';
+ $send[] = str_repeat(" ", 4) . '<tbody>';
+
+ $properties = $this->report->properties;
+
+ foreach ($properties as $key => $value) {
+ $send[] = str_repeat(" ", 4) . '<tr>';
+ $send[] = str_repeat(" ", 8) .
+
+ '<th>' . self::encode($key) . '</th>';
+ $send[] = str_repeat(" ", 8) .
+ '<td>' . self::encode($value) . '</td>';
+
+ $send[] = str_repeat(" ", 4) . '</tr>';
+ }
+ $send[] = str_repeat(" ", 4) . '</tbody>';
+ $send[] = '</table>';
+ $send[] = '';
+
+ return implode("\n", $send);
+ }
}
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
index c541c84..45823e7 100644
--- a/src/Output/MarkdownOutput.php
+++ b/src/Output/MarkdownOutput.php
@@ -1,10 +1,55 @@
<?php
namespace Keruald\Reporting\Output;
class MarkdownOutput extends Output {
public function render () : string {
- return "";
+
+
+ $send = [];
+ $send[] = '# ' . $this->report->title;
+ $send[] = '';
+ foreach ($this->report->sections as $section) {
+ $send[] = '## ' . $section->title;
+ $send[] = '';
+ foreach ($section->entries as $entry) {
+
+ $send[] = '### ' . $entry->title;
+ $send[] = '';
+ $send[] = $entry->text;
+ $send[] = '';
+ }
+ }
+
+ $send[] = '---';
+ $send[] = '';
+ $properties = $this->report->properties;
+ $propertyMaxLength = 0;
+ $maxValue = 0;
+ foreach ($properties as $key => $value) {
+ $propertyMaxLength = max($propertyMaxLength, strlen($key));
+ $maxValue = max($maxValue, strlen($value));
+ }
+ if ($propertyMaxLength < 8) {
+ $propertyMaxLength = 8;
+ }
+
+ $send[] = '| Property' . str_repeat(' ', $propertyMaxLength - 8) . ' | '
+ . str_repeat(' ', $maxValue) . ' |';
+
+ $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
+ . str_repeat('-', $maxValue + 2) . '|';
+
+ foreach ($properties as $key => $value) {
+ $send[] =
+ '| ' . $key . str_repeat(' ', $propertyMaxLength - strlen($key))
+ . ' | '
+ . $value . str_repeat(' ', $maxValue - strlen($value)) . ' |';
+ }
+
+ $send[] = '';
+
+ return implode("\n", $send);
}
}
diff --git a/tests/data/report.html b/tests/data/report.html
index 21c966d..4464df2 100644
--- a/tests/data/report.html
+++ b/tests/data/report.html
@@ -1,43 +1,29 @@
-<!doctype html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport"
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <meta name="X-Report-Date" content="9999-99-99">
- <meta name="X-Report-Topic" content="Urban culture">
- <title>Sneakers</title>
-</head>
-<body>
<h1 id="sneakers">Sneakers</h1>
<h2 id="air-max">Air Max</h2>
<h3 id="air-max-90">Air Max 90</h3>
<p>One of the more icon color is the infrared.</p>
<h3 id="air-max-95">Air Max 95</h3>
<p>Launched in 1995, designed by Sergio Lozano.</p>
<h3 id="air-max-97">Air Max 97</h3>
<p>Well highlighted Air bubble.</p>
<p>Inspired by mountain bikes, while an urban legend quotes Japan bullet trains as inspiration.</p>
<h2 id="other-nike-air">Other Nike Air</h2>
<h3 id="introduction">Introduction</h3>
<p>Because there are other sneakers than Air Max.</p>
<h3 id="air-force-1">Air Force 1</h3>
<p>« Air Force 1. Zéro fan, que des fanatiques. » -- LTA</p>
-<h2 id="👟">👟</h2>
+<h2 id="%F0%9F%91%9F">👟</h2>
<hr>
-<h2 id="ReportProperties">Report properties</h2>
+<h2 id="report-properties">Report properties</h2>
<table>
<tbody>
<tr>
<th>Date</th>
<td>9999-99-99</td>
</tr>
<tr>
<th>Topic</th>
<td>Urban culture</td>
</tr>
</tbody>
</table>
-</body>
-</html>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Sep 14, 08:51 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4081425
Default Alt Text
(5 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment