Skip to content

Commit

Permalink
Fix handling of kebab-case and snake-case files
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiopogliani committed Oct 20, 2020
1 parent b0d429a commit a1369bf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/ComponentTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ protected function parseArguments()

public function decideBlockEnd(Token $token): bool
{
return $token->test('end' . $this->tag);
return $token->test('end' . $this->toCamelCase($this->tag));
}

public function toCamelCase(string $value): string
{
$value = str_replace(['-', '_'], ' ', $value);

$value = ucwords($value);

$value = str_replace(' ', '', $value);

return lcfirst($value);
}

public function getTag(): string
{
return $this->tag;
return $this->toCamelCase($this->tag);
}
}
7 changes: 6 additions & 1 deletion tests/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function render_simple_button_component()

$html = $twig->render('index-button.twig');

$this->assertEquals("<button class=\"bg-blue-600 text-white\"> test </button>\n", $html);
$this->assertEquals(<<<HTML
<button class="bg-blue-600 text-white"> test </button>
<button class="bg-blue-600 text-white"> test </button>
<button class="bg-blue-600 text-white"> test </button>
HTML, $html);
}
}
1 change: 1 addition & 0 deletions tests/templates/components/simple-button.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button {{ attributes.merge({ class: 'text-white' })|raw }}>{{ slot }}</button>
1 change: 1 addition & 0 deletions tests/templates/components/simple_btn.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button {{ attributes.merge({ class: 'text-white' })|raw }}>{{ slot }}</button>
2 changes: 2 additions & 0 deletions tests/templates/index-button.twig
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{% button with {class:'bg-blue-600'} %} test {% endbutton %}
{% simpleButton with {class:'bg-blue-600'} %} test {% endsimpleButton %}
{% simpleBtn with {class:'bg-blue-600'} %} test {% endsimpleBtn %}

0 comments on commit a1369bf

Please sign in to comment.