Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.1",
"8fold/php-xml-builder": "^1.0"
"8fold/php-xml-builder": "^2.0"
},
"require-dev": {
"phpstan/phpstan": "^1.2",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions src/Components/Copyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@

namespace Eightfold\HTMLBuilder\Components;

use Eightfold\XMLBuilder\Contracts\Buildable;

use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
use Stringable;

use Eightfold\HTMLBuilder\Element;

class Copyright implements Buildable
class Copyright implements Stringable
{
use BuildableImp;

private bool $useCopyrightSymbol = true;

private bool $spellOutCopyright = false;
Expand Down
8 changes: 2 additions & 6 deletions src/Components/Favicons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

namespace Eightfold\HTMLBuilder\Components;

use Eightfold\XMLBuilder\Contracts\Buildable;
use Stringable;

use Eightfold\XMLBuilder\Concatenate;

use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;

use Eightfold\HTMLBuilder\Element;

use Eightfold\HTMLBuilder\Components\FaviconMetroColors;
Expand All @@ -17,10 +15,8 @@
* We use https://realfavicongenerator.net to generate favicon-related assets.
* We presume the names of these assets will not be changed.
*/
class Favicons implements Buildable
class Favicons implements Stringable
{
use BuildableImp;

private string $appName = '';

private bool $metroUsesWhite;
Expand Down
12 changes: 4 additions & 8 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@

use Stringable;

use Eightfold\XMLBuilder\Contracts\Buildable;
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;

use Eightfold\HTMLBuilder\Element;

class Document implements Buildable
class Document implements Stringable
{
use BuildableImp;

/**
* @var array<string|Stringable>
*/
Expand Down Expand Up @@ -54,14 +49,15 @@ public function body(string|Stringable ...$content): Document
public function __toString(): string
{
$doctype = '<!doctype html>' . "\n";
return $doctype . Element::html(
$html = (string) Element::html(
Element::head(
Element::title($this->title()),
Element::meta()->omitEndTag()->props($this->charset()),
...$this->headContent()
),
Element::body(...$this->bodyContent())
)->props($this->lang())->build();
)->props($this->lang());
return $doctype . $html;
}

private function title(): string
Expand Down
17 changes: 7 additions & 10 deletions tests/DocumentBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function is_stringable(): void // phpcs:ignore
<html lang="fr"><head><title>title</title><meta charset="ascii"><link rel="stylesheet" href="style.css"><script src="script.js"></script></head><body><p>paragraph content</p></body></html>
html;

$result = (string) Document::create('title', 'fr', 'ascii')
->head(
$result = (string) Document::create('title', 'fr', 'ascii')->head(
Element::link()
->omitEndTag()->props('rel stylesheet', 'href style.css'),
Element::script()->props('src script.js')
Expand All @@ -43,14 +42,13 @@ public function can_have_body(): void // phpcs:ignore
<html lang="fr"><head><title>title</title><meta charset="ascii"><link rel="stylesheet" href="style.css"><script src="script.js"></script></head><body><p>paragraph content</p></body></html>
html;

$result = Document::create('title', 'fr', 'ascii')
->head(
$result = (string) Document::create('title', 'fr', 'ascii')->head(
Element::link()
->omitEndTag()->props('rel stylesheet', 'href style.css'),
Element::script()->props('src script.js')
)->body(
Element::p('paragraph content')
)->build();
);

$this->assertSame($expected, $result);
}
Expand All @@ -65,12 +63,11 @@ public function can_have_head(): void // phpcs:ignore
<html lang="fr"><head><title>title</title><meta charset="ascii"><link rel="stylesheet" href="style.css"><script src="script.js"></script></head><body></body></html>
html;

$result = Document::create('title', 'fr', 'ascii')
->head(
$result = (string) Document::create('title', 'fr', 'ascii')->head(
Element::link()
->omitEndTag()->props('rel stylesheet', 'href style.css'),
Element::script()->props('src script.js')
)->build();
);

$this->assertSame($expected, $result);
}
Expand All @@ -85,7 +82,7 @@ public function can_change_lang_and_char_set(): void // phpcs:ignore
<html lang="fr"><head><title>title</title><meta charset="ascii"></head><body></body></html>
html;

$result = Document::create('title', 'fr', 'ascii')->build();
$result = (string) Document::create('title', 'fr', 'ascii');

$this->assertSame($expected, $result);
}
Expand All @@ -100,7 +97,7 @@ public function has_baseline(): void // phpcs:ignore
<html lang="en"><head><title>title</title><meta charset="utf-8"></head><body></body></html>
html;

$result = Document::create('title')->build();
$result = (string) Document::create('title');

$this->assertSame($expected, $result);
}
Expand Down
7 changes: 3 additions & 4 deletions tests/ElementBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ public function has_ordered_properties(): void // phpcs:ignore
<a id="unique" class="some-style" href="https://8fold.pro" data-testing="test" required>link</a>
html;

$result = Element::a('link')
->props(
$result = (string) Element::a('link')->props(
'required required',
'href https://8fold.pro',
'class some-style',
'id unique',
'data-testing test'
)->build();
);

$this->assertSame($expected, $result);
}
Expand All @@ -53,7 +52,7 @@ public function has_correct_selfclosing_string(): void // phpcs:ignore
<tag>
html;

$result = Element::tag()->omitEndTag()->build();
$result = (string) Element::tag()->omitEndTag();

$this->assertSame($expected, $result);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/ElementExtensionBaselineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ public function has_ordered_properties(): void // phpcs:ignore
<a class="some-style" href="https://8fold.pro" id="unique" data-testing="test" required>link</a>
html;

$result = ElementExtension::a('link')
->props(
$result = (string) ElementExtension::a('link')->props(
'required required',
'href https://8fold.pro',
'class some-style',
'id unique',
'data-testing test'
)->build();
);

$this->assertSame($exptected, $result);
}
Expand Down