Page MenuHomeDevCentral

D2505.id6318.diff
No OneTemporary

D2505.id6318.diff

diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
--- a/src/Output/HTMLOutput.php
+++ b/src/Output/HTMLOutput.php
@@ -4,9 +4,47 @@
class HTMLOutput extends Output {
- public function print () : string {
- // TODO: Implement print() method.
- return "";
+ private function makeId($name) : string {
+ return strtolower(str_replace(' ', '-', $name));
}
+ public function render () : string {
+ $report = $this->report;
+ $send = [];
+ $title = $report->title;
+ $send[] = '<h1 id="'.$this->makeId($title).'">'.$title.'</h1>';
+
+ foreach ($report->sections as $key => $section) {
+ $title = $section->title;
+ $send[] ='<h2 id="'.$this->makeId($title).'">'.$title.'</h2>';
+ foreach ($section->entries as $key => $entry) {
+ $title = $entry->title;
+ $send[] = '<h3 id="'.$this->makeId($title).'">'.$title.'</h3>';
+
+ $text = explode("\n\n", $entry->text);
+
+ foreach ($text as $key => $value) {
+ $send[] = '<p>'.$value.'</p>';
+ }
+ }
+ }
+ $send[] = '<hr>';
+
+ $send[] = '<h2 id="report-properties">Report properties</h2>';
+ $send[] = '<table>';
+ $send[] = ' <tbody>';
+
+ $properties = $report->properties;
+
+ foreach ($properties as $key => $value) {
+ $send[] = ' <tr>';
+ $send[] = ' <th>'.$key.'</th>';
+ $send[] = ' <td>'.$value.'</td>';
+ $send[] = ' </tr>';
+ }
+ $send[] = ' </tbody>';
+ $send[] = '</table>';
+ $send[] = '';
+ return implode("\n", $send);
+ }
}
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
--- a/src/Output/MarkdownOutput.php
+++ b/src/Output/MarkdownOutput.php
@@ -4,8 +4,48 @@
class MarkdownOutput extends Output {
- public function print () : string {
- // TODO: Implement print() method.
- return "";
+ public function render () : string {
+
+ $report = $this->report;
+ $send = [];
+ $send[] = '# '.$report->title;
+ $send[] = '';
+ foreach ($report->sections as $key => $section) {
+ $send[] ='## '. $section->title;
+ $send[] = '';
+ foreach ($section->entries as $key => $entry) {
+
+ $send[] = '### '.$entry->title;
+ $send[] = '';
+ $send[] = $entry->text;
+ $send[] = '';
+ }
+ }
+
+ $send[] = '---';
+ $send[] = '';
+ $properties = $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/src/Output/Output.php b/src/Output/Output.php
--- a/src/Output/Output.php
+++ b/src/Output/Output.php
@@ -16,7 +16,7 @@
/// Abstract methods to implement
///
- public abstract function print() : string;
+ public abstract function render() : string;
///
/// Constructors
diff --git a/tests/Output/HTMLOutputTest.php b/tests/Output/HTMLOutputTest.php
--- a/tests/Output/HTMLOutputTest.php
+++ b/tests/Output/HTMLOutputTest.php
@@ -28,7 +28,7 @@
public function testPrint() : void {
$actual = HTMLOutput::for($this->report)
- ->print();
+ ->render();
$expected = file_get_contents($this->getDataDir() . "/report.html");
diff --git a/tests/Output/MarkdownOutputTest.php b/tests/Output/MarkdownOutputTest.php
--- a/tests/Output/MarkdownOutputTest.php
+++ b/tests/Output/MarkdownOutputTest.php
@@ -28,7 +28,7 @@
public function testPrint() : void {
$actual = MarkdownOutput::for($this->report)
- ->print();
+ ->render();
$expected = file_get_contents($this->getDataDir() . "/report.md");
diff --git a/tests/data/report.html b/tests/data/report.html
--- a/tests/data/report.html
+++ b/tests/data/report.html
@@ -1,15 +1,3 @@
-<!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>
@@ -24,9 +12,9 @@
<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>
-<h3 id="👟">👟</h3>
+<h2 id="👟">👟</h2>
<hr>
-<h2 id="ReportProperties">Report properties</h2>
+<h2 id="report-properties">Report properties</h2>
<table>
<tbody>
<tr>
@@ -39,5 +27,3 @@
</tr>
</tbody>
</table>
-</body>
-</html>
diff --git a/tests/data/report.md b/tests/data/report.md
--- a/tests/data/report.md
+++ b/tests/data/report.md
@@ -26,7 +26,7 @@
« Air Force 1. Zéro fan, que des fanatiques. » -- LTA
-### 👟
+## 👟
---

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 09:00 (21 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247310
Default Alt Text
D2505.id6318.diff (5 KB)

Event Timeline