-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from awcodes/feat/block-stubs
Feat: make:filament-block command
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 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,108 @@ | ||
<?php | ||
|
||
namespace FilamentTiptapEditor\Commands; | ||
|
||
use Filament\Support\Commands\Concerns\CanManipulateFiles; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Str; | ||
use function Laravel\Prompts\text; | ||
|
||
class MakeBlockCommand extends Command | ||
{ | ||
use CanManipulateFiles; | ||
|
||
protected $description = 'Create a new Tiptap Editor block'; | ||
|
||
protected $signature = 'make:tiptap-block {name?} {--F|force}'; | ||
|
||
public function handle(): int | ||
{ | ||
$block = (string) str( | ||
$this->argument('name') ?? | ||
text( | ||
label: 'What is the block name?', | ||
placeholder: 'CustomBlock', | ||
required: true, | ||
), | ||
) | ||
->trim('/') | ||
->trim('\\') | ||
->trim(' ') | ||
->replace('/', '\\'); | ||
|
||
$blockClass = (string) str($block)->afterLast('\\'); | ||
$blockNamespace = str($block)->contains('\\') | ||
? (string) str($block)->beforeLast('\\') | ||
: ''; | ||
|
||
$namespace = 'App\\TiptapBlocks'; | ||
|
||
$path = app_path('TiptapBlocks/'); | ||
|
||
$preview = str($block) | ||
->prepend( | ||
(string) str("{$namespace}\\Previews\\") | ||
->replaceFirst('App\\', '') | ||
) | ||
->replace('\\', '/') | ||
->explode('/') | ||
->map(fn ($segment) => Str::lower(Str::kebab($segment))) | ||
->implode('.'); | ||
|
||
$rendered = str($block) | ||
->prepend( | ||
(string) str("{$namespace}\\Rendered\\") | ||
->replaceFirst('App\\', '') | ||
) | ||
->replace('\\', '/') | ||
->explode('/') | ||
->map(fn ($segment) => Str::lower(Str::kebab($segment))) | ||
->implode('.'); | ||
|
||
$path = (string) str($block) | ||
->prepend('/') | ||
->prepend($path ?? '') | ||
->replace('\\', '/') | ||
->replace('//', '/') | ||
->append('.php'); | ||
|
||
$previewPath = resource_path( | ||
(string) str($preview) | ||
->replace('.', '/') | ||
->prepend('views/') | ||
->append('.blade.php'), | ||
); | ||
|
||
$renderedViewPath = resource_path( | ||
(string) str($rendered) | ||
->replace('.', '/') | ||
->prepend('views/') | ||
->append('.blade.php'), | ||
); | ||
|
||
$files = [ | ||
$path, | ||
$previewPath, | ||
$renderedViewPath, | ||
]; | ||
|
||
if (! $this->option('force') && $this->checkForCollision($files)) { | ||
return static::INVALID; | ||
} | ||
|
||
$this->copyStubToApp('Block', $path, [ | ||
'class' => $blockClass, | ||
'namespace' => str($namespace) . ($blockNamespace !== '' ? "\\{$blockNamespace}" : ""), | ||
'preview' => $preview, | ||
'rendered' => $rendered, | ||
]); | ||
|
||
$this->copyStubToApp('Preview', $previewPath); | ||
|
||
$this->copyStubToApp('Rendered', $renderedViewPath); | ||
|
||
$this->components->info("Tiptap Editor Block [{$path}] created successfully."); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use FilamentTiptapEditor\TiptapBlock; | ||
|
||
class {{ class }} extends TiptapBlock | ||
{ | ||
public string $preview = '{{ preview }}'; | ||
|
||
public string $rendered = '{{ rendered }}'; | ||
|
||
public function getFormSchema(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
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,3 @@ | ||
<div> | ||
// block preview in editor | ||
</div> |
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,3 @@ | ||
<div> | ||
// rendered block view outside editor | ||
</div> |