Skip to content

Commit f5e38d0

Browse files
authored
refactor(view): is_void_tag (#1037)
1 parent 4d534fe commit f5e38d0

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/Tempest/Support/src/Html/functions.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use function Tempest\Support\arr;
99

1010
/**
11-
* Determines whether the specified HTML tag is self-closing.
11+
* Determines whether the specified HTML tag is a void tag.
12+
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
1213
*/
13-
function is_self_closing_tag(Stringable|string $tag): bool
14+
function is_void_tag(Stringable|string $tag): bool
1415
{
1516
return in_array(
1617
(string) $tag,
@@ -50,7 +51,7 @@ function create_tag(string $tag, array $attributes = [], ?string $content = null
5051
)
5152
->toString();
5253

53-
if ($content || ! is_self_closing_tag($tag)) {
54+
if ($content || ! is_void_tag($tag)) {
5455
return new HtmlString(sprintf('<%s%s>%s</%s>', $tag, $attributes, $content ?? '', $tag));
5556
}
5657

src/Tempest/View/src/Elements/GenericElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Tempest\View\Element;
88

9-
use function Tempest\Support\Html\is_self_closing_tag;
9+
use function Tempest\Support\Html\is_void_tag;
1010
use function Tempest\Support\str;
1111

1212
final class GenericElement implements Element
@@ -69,7 +69,7 @@ public function compile(): string
6969
}
7070

7171
// Void elements
72-
if (is_self_closing_tag($this->tag)) {
72+
if (is_void_tag($this->tag)) {
7373
return "<{$this->tag}{$attributes}>";
7474
}
7575

src/Tempest/View/src/Renderers/TempestViewCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Tempest\View\View;
1818

1919
use function Tempest\Support\arr;
20-
use function Tempest\Support\Html\is_self_closing_tag;
20+
use function Tempest\Support\Html\is_void_tag;
2121
use function Tempest\Support\path;
2222
use function Tempest\Support\str;
2323

@@ -113,7 +113,7 @@ private function parseDom(string $template): NodeList
113113
replace: function (array $match) {
114114
$element = str($match['element'])->trim();
115115

116-
if (is_self_closing_tag($element)) {
116+
if (is_void_tag($element)) {
117117
// Void tags must not have a closing tag
118118
return sprintf('<%s>', $element->toString());
119119
}

0 commit comments

Comments
 (0)