-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #3 add command to create new modules on the fly
- Loading branch information
Showing
2 changed files
with
78 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,61 @@ | ||
<?php | ||
|
||
namespace Plank\Contentable\Commands; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
|
||
#[AsCommand(name: 'make:content')] | ||
class ContentMakeCommand extends GeneratorCommand | ||
{ | ||
protected $signature = "make:content {name}"; | ||
|
||
protected $description = "Create a new content model class to act as a receptacle for content"; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Model'; | ||
|
||
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?')) { | ||
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'; | ||
} | ||
|
||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Plank\Contentable\Concerns\CanRender; | ||
use Plank\Contentable\Models\Module; | ||
|
||
class {{ class }} extends Module | ||
{ | ||
use HasFactory; | ||
|
||
public function renderHtml() { | ||
// TODO: Replace generated stubs | ||
return ""; | ||
} | ||
} |