From 085ec957ca058ceda4451b052c6a26489f1081b1 Mon Sep 17 00:00:00 2001 From: Michel Bardelmeijer Date: Mon, 23 Nov 2020 21:13:47 +0100 Subject: [PATCH] Kebab case component names --- README.md | 3 +++ src/LivewireTokenParser.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3932a7d..8f66cc9 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ class Counter extends Component } ``` +## Caveats +- Components with hyphens cannot be called like `{% livewire foo-bar %}` as Twig doesn't allow hyphens like that. We've added a workaround for this by allowing camel case: `{% livewire fooBar %}` + ## Todo - [ ] Implement support for `key` tracking - [ ] Implement support for preserving child tracking diff --git a/src/LivewireTokenParser.php b/src/LivewireTokenParser.php index d580f14..a857486 100644 --- a/src/LivewireTokenParser.php +++ b/src/LivewireTokenParser.php @@ -2,6 +2,7 @@ namespace Enflow\LivewireTwig; +use Illuminate\Support\Str; use Twig\Token; use Twig\TokenParser\AbstractTokenParser; @@ -18,7 +19,7 @@ public function parse(Token $token): LivewireNode $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new LivewireNode($component, $variables, $token->getLine(), $this->getTag()); + return new LivewireNode(Str::kebab($component), $variables, $token->getLine(), $this->getTag()); } public function getTag(): string