From 3f36bdac3187e0cd4cf5d80503a647b32dd8f8c8 Mon Sep 17 00:00:00 2001 From: Massimo Triassi Date: Mon, 20 Nov 2023 15:55:12 -0500 Subject: [PATCH 1/4] feat: #3 add base module to extend all modules from --- src/Models/Module.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Models/Module.php diff --git a/src/Models/Module.php b/src/Models/Module.php new file mode 100644 index 0000000..ee97261 --- /dev/null +++ b/src/Models/Module.php @@ -0,0 +1,13 @@ + Date: Mon, 20 Nov 2023 17:00:55 -0500 Subject: [PATCH 2/4] feat: #3 add command to create new modules on the fly --- src/Commands/ContentMakeCommand.php | 61 +++++++++++++++++++++++++++++ src/Commands/stubs/content.php.stub | 17 ++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/Commands/ContentMakeCommand.php create mode 100644 src/Commands/stubs/content.php.stub diff --git a/src/Commands/ContentMakeCommand.php b/src/Commands/ContentMakeCommand.php new file mode 100644 index 0000000..81122cd --- /dev/null +++ b/src/Commands/ContentMakeCommand.php @@ -0,0 +1,61 @@ +confirm('Would you like to use App\\Models\\Content as the name space for all generated content?')) { + File::makeDirectory(app_path('Models/Content')); + } + + parent::handle(); + } + + protected function getStub() + { + return $this->resolveStubPath("/stubs/content.php.stub"); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return is_dir(app_path('Models/Content')) ? $rootNamespace.'\\Models\\Content' : $rootNamespace.'\\Models'; + } + +} \ No newline at end of file diff --git a/src/Commands/stubs/content.php.stub b/src/Commands/stubs/content.php.stub new file mode 100644 index 0000000..f33e71b --- /dev/null +++ b/src/Commands/stubs/content.php.stub @@ -0,0 +1,17 @@ + Date: Mon, 20 Nov 2023 17:01:18 -0500 Subject: [PATCH 3/4] feat: #3 register content make command to package --- src/ContentableServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ContentableServiceProvider.php b/src/ContentableServiceProvider.php index 5fa725a..bd86f1a 100644 --- a/src/ContentableServiceProvider.php +++ b/src/ContentableServiceProvider.php @@ -2,6 +2,7 @@ namespace Plank\Contentable; +use Plank\Contentable\Commands\ContentMakeCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -11,6 +12,7 @@ public function configurePackage(Package $package): void { $package ->name('contentable') + ->hasCommand(ContentMakeCommand::class) ->hasConfigFile() ->hasMigrations([ 'create_contents_table', From 7ef0a891905a1bc2d538a5c0041cab1c1f2eb176 Mon Sep 17 00:00:00 2001 From: m-triassi Date: Mon, 20 Nov 2023 22:01:43 +0000 Subject: [PATCH 4/4] Fix styling --- src/Commands/ContentMakeCommand.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Commands/ContentMakeCommand.php b/src/Commands/ContentMakeCommand.php index 81122cd..bee702e 100644 --- a/src/Commands/ContentMakeCommand.php +++ b/src/Commands/ContentMakeCommand.php @@ -9,9 +9,9 @@ #[AsCommand(name: 'make:content')] class ContentMakeCommand extends GeneratorCommand { - protected $signature = "make:content {name}"; + protected $signature = 'make:content {name}'; - protected $description = "Create a new content model class to act as a receptacle for content"; + protected $description = 'Create a new content model class to act as a receptacle for content'; /** * The type of class being generated. @@ -22,7 +22,7 @@ class ContentMakeCommand extends GeneratorCommand public function handle() { - if (!is_dir(app_path('Models/Content')) && $this->confirm('Would you like to use App\\Models\\Content as the name space for all generated content?')) { + if (! is_dir(app_path('Models/Content')) && $this->confirm('Would you like to use App\\Models\\Content as the name space for all generated content?')) { File::makeDirectory(app_path('Models/Content')); } @@ -31,7 +31,7 @@ public function handle() protected function getStub() { - return $this->resolveStubPath("/stubs/content.php.stub"); + return $this->resolveStubPath('/stubs/content.php.stub'); } /** @@ -57,5 +57,4 @@ protected function getDefaultNamespace($rootNamespace) { return is_dir(app_path('Models/Content')) ? $rootNamespace.'\\Models\\Content' : $rootNamespace.'\\Models'; } - -} \ No newline at end of file +}