Skip to content

Commit 5a31e40

Browse files
committed
Support for vendor components
Fixes N1ebieski#10
1 parent 408e8fe commit 5a31e40

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

php-templates/blade-components.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function all()
1919
$this->getAnonymousNamespaced(),
2020
$this->getAnonymous(),
2121
$this->getAliases(),
22+
$this->getVendorComponents(),
2223
))->groupBy('key')->map(fn($items) => [
2324
'isVendor' => $items->first()['isVendor'],
2425
'paths' => $items->pluck('path')->values(),
@@ -193,6 +194,40 @@ protected function getAnonymous()
193194
return $components;
194195
}
195196

197+
protected function getVendorComponents(): array
198+
{
199+
$components = [];
200+
201+
/** @var \Illuminate\View\Factory $view */
202+
$view = \Illuminate\Support\Facades\App::make('view');
203+
204+
/** @var \Illuminate\View\FileViewFinder $finder */
205+
$finder = $view->getFinder();
206+
207+
/** @var array<string, array<int, string>> $views */
208+
$views = $finder->getHints();
209+
210+
foreach ($views as $key => $paths) {
211+
// First is always optional override in the resources/views folder
212+
$path = $paths[0].'/components';
213+
214+
if (! is_dir($path)) {
215+
continue;
216+
}
217+
218+
array_push(
219+
$components,
220+
...$this->findFiles(
221+
$path,
222+
'blade.php',
223+
fn (\Illuminate\Support\Stringable $k) => $k->kebab()->prepend($key.'::'),
224+
)
225+
);
226+
}
227+
228+
return $components;
229+
}
230+
196231
protected function handleIndexComponents($str)
197232
{
198233
if ($str->endsWith('.index')) {

src/templates/blade-components.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $components = new class {
1919
$this->getAnonymousNamespaced(),
2020
$this->getAnonymous(),
2121
$this->getAliases(),
22+
$this->getVendorComponents(),
2223
))->groupBy('key')->map(fn($items) => [
2324
'isVendor' => $items->first()['isVendor'],
2425
'paths' => $items->pluck('path')->values(),
@@ -193,6 +194,40 @@ $components = new class {
193194
return $components;
194195
}
195196
197+
protected function getVendorComponents(): array
198+
{
199+
$components = [];
200+
201+
/** @var \\Illuminate\\View\\Factory $view */
202+
$view = \\Illuminate\\Support\\Facades\\App::make('view');
203+
204+
/** @var \\Illuminate\\View\\FileViewFinder $finder */
205+
$finder = $view->getFinder();
206+
207+
/** @var array<string, array<int, string>> $views */
208+
$views = $finder->getHints();
209+
210+
foreach ($views as $key => $paths) {
211+
// First is always optional override in the resources/views folder
212+
$path = $paths[0].'/components';
213+
214+
if (! is_dir($path)) {
215+
continue;
216+
}
217+
218+
array_push(
219+
$components,
220+
...$this->findFiles(
221+
$path,
222+
'blade.php',
223+
fn (\\Illuminate\\Support\\Stringable $k) => $k->kebab()->prepend($key.'::'),
224+
)
225+
);
226+
}
227+
228+
return $components;
229+
}
230+
196231
protected function handleIndexComponents($str)
197232
{
198233
if ($str->endsWith('.index')) {

0 commit comments

Comments
 (0)