Skip to content

Commit

Permalink
Fix #71: Add methods Script::getContent() and Style::getContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed May 4, 2021
1 parent 5d05f39 commit 2aa2db0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Enh #70: Add support `\Stringable` as content in methods `Html::tag()`, `Html::normalTag()`, `Html::a()`,
`Html::label()`, `Html::option()`, `Html::div()`, `Html::span()`, `Html::p()`, `Html::li()`, `Html::caption()`,
`Html::td()`, `Html::th()` (vjik)
- Enh #71: Add methods `Script::getContent()` and `Style::getContent()` (vjik)

## 1.1.0 April 09, 2021

Expand Down
5 changes: 5 additions & 0 deletions src/Tag/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function content(string $content): self
return $new;
}

public function getContent(): string
{
return $this->content;
}

/**
* Alias for {@see src}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Tag/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function content(string $content): self
return $new;
}

public function getContent(): string
{
return $this->content;
}

public function media(?string $media): self
{
$new = clone $this;
Expand Down
9 changes: 5 additions & 4 deletions tests/common/Tag/ScriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public function testBase(): void

public function testContent(): void
{
$this->assertSame(
'<script>alert("4 > 2");</script>',
Script::tag()->content('alert("4 > 2");')->render()
);
$content = 'alert("4 > 2");';
$tag = Script::tag()->content($content);

$this->assertSame($content, $tag->getContent());
$this->assertSame('<script>' . $content . '</script>', $tag->render());
}

public function dataUrl(): array
Expand Down
9 changes: 5 additions & 4 deletions tests/common/Tag/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public function testBase(): void

public function testContent(): void
{
$this->assertSame(
'<style>body { display: block }</style>',
Style::tag()->content('body { display: block }')->render()
);
$content = 'body { display: block }';
$tag = Style::tag()->content($content);

$this->assertSame($content, $tag->getContent());
$this->assertSame('<style>' . $content . '</style>', $tag->render());
}

public function dataMedia(): array
Expand Down

0 comments on commit 2aa2db0

Please sign in to comment.