Skip to content

Commit 2e81284

Browse files
committed
handle index components universally
1 parent 0947c59 commit 2e81284

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

php-templates/blade-components.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ protected function findFiles($path, $extension, $keyCallback = null)
5757
->replace($pathRealPath, '')
5858
->ltrim('/\\')
5959
->replace('.' . $extension, '')
60-
->replace(['/', '\\'], '.');
60+
->replace(['/', '\\'], '.')
61+
->pipe(fn($str) => $this->handleIndexComponents($str));
6162

6263
$components[] = [
6364
"path" => LaravelVsCode::relativePath($realPath),
@@ -138,26 +139,7 @@ protected function getAnonymous()
138139
fn($key) => $key
139140
->kebab()
140141
->prepend(($item['prefix'] ?? ':') . ':')
141-
->ltrim(':')
142-
->when(true, function ($str) {
143-
if ($str->endsWith('.index')) {
144-
return $str->replaceLast('.index', '');
145-
}
146-
147-
if (!$str->contains('.')) {
148-
return $str;
149-
}
150-
151-
$parts = $str->explode('.');
152-
153-
if ($parts->slice(-2)->unique()->count() === 1) {
154-
$parts->pop();
155-
156-
return $str->of($parts->implode('.'));
157-
}
158-
159-
return $str;
160-
})
142+
->ltrim(':'),
161143
)
162144
);
163145

@@ -169,6 +151,27 @@ protected function getAnonymous()
169151
return $components;
170152
}
171153

154+
protected function handleIndexComponents($str)
155+
{
156+
if ($str->endsWith('.index')) {
157+
return $str->replaceLast('.index', '');
158+
}
159+
160+
if (!$str->contains('.')) {
161+
return $str;
162+
}
163+
164+
$parts = $str->explode('.');
165+
166+
if ($parts->slice(-2)->unique()->count() === 1) {
167+
$parts->pop();
168+
169+
return \Illuminate\Support\Str::of($parts->implode('.'));
170+
}
171+
172+
return $str;
173+
}
174+
172175
protected function getNamespaced()
173176
{
174177
$namespaced = \Illuminate\Support\Facades\Blade::getClassComponentNamespaces();

src/templates/blade-components.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ $components = new class {
5757
->replace($pathRealPath, '')
5858
->ltrim('/\\\\')
5959
->replace('.' . $extension, '')
60-
->replace(['/', '\\\\'], '.');
60+
->replace(['/', '\\\\'], '.')
61+
->pipe(fn($str) => $this->handleIndexComponents($str));
6162
6263
$components[] = [
6364
"path" => LaravelVsCode::relativePath($realPath),
@@ -138,26 +139,7 @@ $components = new class {
138139
fn($key) => $key
139140
->kebab()
140141
->prepend(($item['prefix'] ?? ':') . ':')
141-
->ltrim(':')
142-
->when(true, function ($str) {
143-
if ($str->endsWith('.index')) {
144-
return $str->replaceLast('.index', '');
145-
}
146-
147-
if (!$str->contains('.')) {
148-
return $str;
149-
}
150-
151-
$parts = $str->explode('.');
152-
153-
if ($parts->slice(-2)->unique()->count() === 1) {
154-
$parts->pop();
155-
156-
return $str->of($parts->implode('.'));
157-
}
158-
159-
return $str;
160-
})
142+
->ltrim(':'),
161143
)
162144
);
163145
@@ -169,6 +151,27 @@ $components = new class {
169151
return $components;
170152
}
171153
154+
protected function handleIndexComponents($str)
155+
{
156+
if ($str->endsWith('.index')) {
157+
return $str->replaceLast('.index', '');
158+
}
159+
160+
if (!$str->contains('.')) {
161+
return $str;
162+
}
163+
164+
$parts = $str->explode('.');
165+
166+
if ($parts->slice(-2)->unique()->count() === 1) {
167+
$parts->pop();
168+
169+
return \\Illuminate\\Support\\Str::of($parts->implode('.'));
170+
}
171+
172+
return $str;
173+
}
174+
172175
protected function getNamespaced()
173176
{
174177
$namespaced = \\Illuminate\\Support\\Facades\\Blade::getClassComponentNamespaces();

0 commit comments

Comments
 (0)