Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Add support for setting widget description during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Aug 13, 2024
1 parent cb3913d commit f15c77e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Console/WidgetMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Log1x\AcfComposer\Console;

use Illuminate\Support\Str;

use function Laravel\Prompts\text;

class WidgetMakeCommand extends MakeCommand
{
/**
Expand Down Expand Up @@ -33,6 +37,31 @@ class WidgetMakeCommand extends MakeCommand
*/
protected $view = 'widget';

/**
* {@inheritdoc}
*/
public function buildClass($name)
{
$stub = parent::buildClass($name);

$name = Str::of($name)
->afterLast('\\')
->kebab()
->headline()
->replace('-', ' ');

$description = "A beautiful {$name} widget.";

$description = text(
label: 'Enter the widget description',
placeholder: $description,
) ?: $description;

$stub = str_replace('DummyDescription', $description, $stub);

return $stub;
}

/**
* Get the stub file for the generator.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/widget.stub
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DummyClass extends Widget
*
* @var string
*/
public $description = 'This is a DummyTitle widget.';
public $description = 'DummyDescription';

/**
* Data to be passed to the widget before rendering.
Expand Down

0 comments on commit f15c77e

Please sign in to comment.