Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/Commands/ContentMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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';
}
}
17 changes: 17 additions & 0 deletions src/Commands/stubs/content.php.stub
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 "";
}
}
2 changes: 2 additions & 0 deletions src/ContentableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Plank\Contentable;

use Plank\Contentable\Commands\ContentMakeCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -11,6 +12,7 @@ public function configurePackage(Package $package): void
{
$package
->name('contentable')
->hasCommand(ContentMakeCommand::class)
->hasConfigFile()
->hasMigrations([
'create_contents_table',
Expand Down
13 changes: 13 additions & 0 deletions src/Models/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Plank\Contentable\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Plank\Contentable\Concerns\CanRender;

class Module extends Model
{
use CanRender;
use HasFactory;
}