-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass twig false as vue false in forum/submit.twig
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 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,20 @@ | ||
<?php | ||
namespace Coyote\Services\TwigBridge\Extensions; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
class Vue extends AbstractExtension | ||
{ | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('vueBoolean', $this->vueBoolean(...)), | ||
]; | ||
} | ||
|
||
private function vueBoolean(bool $value): string | ||
{ | ||
return $value ? 'true' : 'false'; | ||
} | ||
} |
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
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
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,41 @@ | ||
<?php | ||
namespace Tests\Unit\Vue; | ||
|
||
use Coyote\Domain\Html; | ||
use Coyote\Services\TwigBridge\Extensions\Vue; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig\Environment; | ||
use Twig\Loader\ArrayLoader; | ||
use Twig\Runtime\EscaperRuntime; | ||
|
||
class TwigExtensionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function booleanTrue(): void | ||
{ | ||
$this->assertSame( | ||
'true', | ||
$this->twig("{{ vueBoolean(value) }}", [ | ||
'value' => true, | ||
])); | ||
} | ||
|
||
#[Test] | ||
public function booleanFalse(): void | ||
{ | ||
$this->assertSame( | ||
'false', | ||
$this->twig("{{ vueBoolean(value) }}", [ | ||
'value' => false, | ||
])); | ||
} | ||
|
||
private function twig(string $sourceCode, array $values): string | ||
{ | ||
$twig = new Environment(new ArrayLoader()); | ||
$twig->getRuntime(EscaperRuntime::class)->addSafeClass(Html::class, ['html']); | ||
$twig->addExtension(new Vue()); | ||
return $twig->createTemplate($sourceCode)->render($values); | ||
} | ||
} |