-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace VolkmannDesignCode\KirbyUtils; | ||
|
||
use Kirby\Cms\File; | ||
use Kirby\Toolkit\A; | ||
use Kirby\Toolkit\Html; | ||
use Kirby\Toolkit\Str; | ||
|
||
class HtmlHelpers { | ||
|
||
static function svgWithClass(string|File $file, string|array $classes): string|null { | ||
$classNames = is_string($classes) ? [$classes] : $classes; | ||
$class = Html::attr('class', A::join($classNames, ' ')); | ||
return Str::replace(svg($file), '<svg', '<svg ' . $class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Kirby\Cms\App; | ||
use PHPUnit\Framework\TestCase; | ||
use VolkmannDesignCode\KirbyUtils\HtmlHelpers; | ||
|
||
final class HtmlHelpersTest extends TestCase | ||
{ | ||
public function testSvgWithClasses(): void | ||
{ | ||
$svgPath = App::instance()->root() . '/tests/fixtures/kirby.svg'; | ||
$regular = svg($svgPath); | ||
$this->assertStringStartsNotWith($regular, '<svg class="'); | ||
|
||
$withClass = HtmlHelpers::svgWithClass($svgPath, 'kirby'); | ||
$this->assertStringStartsWith('<svg class="kirby"', $withClass); | ||
|
||
$withMultipleClasses = HtmlHelpers::svgWithClass($svgPath, ['kirby', 'icon']); | ||
$this->assertStringStartsWith('<svg class="kirby icon"', $withMultipleClasses); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.