Skip to content

Commit

Permalink
Generators HTML/Markdown: don't print header/footer when there are no…
Browse files Browse the repository at this point in the history
… docs

As things were, the Markdown/HTML header and footer would always be printed, even if there were no docs to display.

In my opinion, there should be no output if there are no docs. This is in line with the `Text` output, which would already not generate any output when there are no docs.

Includes updated test expectations.
  • Loading branch information
jrfnl committed Nov 15, 2024
1 parent f9c5f18 commit da49da0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 82 deletions.
4 changes: 4 additions & 0 deletions src/Generators/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class HTML extends Generator
*/
public function generate()
{
if (empty($this->docFiles) === true) {
return;
}

ob_start();
$this->printHeader();
$this->printToc();
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Markdown extends Generator
*/
public function generate()
{
if (empty($this->docFiles) === true) {
return;
}

ob_start();
$this->printHeader();

Expand Down
78 changes: 0 additions & 78 deletions tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html

This file was deleted.

2 changes: 0 additions & 2 deletions tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Core/Generators/HTMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function dataDocs()
return [
'Standard without docs' => [
'standard' => __DIR__.'/NoDocsTest.xml',
'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputNoDocs.html',
'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
'Standard with one doc file' => [
'standard' => __DIR__.'/OneDocTest.xml',
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Generators/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function dataDocs()
return [
'Standard without docs' => [
'standard' => __DIR__.'/NoDocsTest.xml',
'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputNoDocs.md',
'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
'Standard with one doc file' => [
'standard' => __DIR__.'/OneDocTest.xml',
Expand Down

0 comments on commit da49da0

Please sign in to comment.