-
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.
- Loading branch information
Showing
8 changed files
with
207 additions
and
13 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
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,87 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Console\Commands; | ||
|
||
class ModuleMakeViewCommand extends ModuleMakerCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'module:make:view | ||
{name : The name of the view} | ||
{--module= : Name of module migration should belong to} | ||
{--test : Generate an accompanying PHPUnit test for the View} | ||
{--pest : Generate an accompanying Pest test for the View}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generate view resource for a module'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'view'; | ||
|
||
public function handle() | ||
{ | ||
$module = $this->getModuleInput(); | ||
$filename = $this->getNameInput(); | ||
$folder = $this->getFolderPath(); | ||
|
||
$name = $this->qualifyClass($module.'\\'.$folder.'\\'.$filename); | ||
|
||
if ($this->files->exists($path = $this->getPath($name, 'blade.php'))) { | ||
$this->logFileExist($name); | ||
|
||
return true; | ||
} | ||
|
||
$type = ''; | ||
|
||
$this->setStubFile("view.{$type}"); | ||
$this->makeDirectory($path); | ||
$this->files->put($path, $this->buildClass($name)); | ||
|
||
$this->logFileCreated($name); | ||
|
||
$folder = 'Tests/Feature'; | ||
if ($this->option('pest')) { | ||
$this->call( | ||
ModuleMakeTestCommand::class, | ||
[ | ||
'name' => ($filename), | ||
'--module' => $module, | ||
'--pest' => true, | ||
'--view' => true, | ||
] | ||
); | ||
$type = 'pest.'; | ||
} | ||
|
||
if ($this->option('test')) { | ||
$this->call( | ||
ModuleMakeTestCommand::class, | ||
[ | ||
'name' => $filename, | ||
'--module' => $module, | ||
'--view' => true, | ||
] | ||
); | ||
$type = 'test.'; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected function getFolderPath(): string | ||
{ | ||
return 'Views'; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
it('can render', function () { | ||
$contents = $this->view('{{moduleName}}::{{viewFile}}', [ | ||
// | ||
]); | ||
|
||
$contents->assertSee(''); | ||
}); |
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,20 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Tests\TestCase; | ||
|
||
class {{ class }} extends TestCase | ||
{ | ||
/** | ||
* A basic view test example. | ||
*/ | ||
public function test_it_can_render(): void | ||
{ | ||
$contents = $this->view('{{moduleName}}::{{viewFile}}', [ | ||
// | ||
]); | ||
|
||
$contents->assertSee(''); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Closure; | ||
use Illuminate\View\Component; | ||
use Illuminate\Contracts\View\View; | ||
|
||
class {{ class }} extends Component | ||
{ | ||
/** | ||
* Create a new component instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
public function render(): View|Closure|string | ||
{ | ||
return {{ view }}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
<?php | ||
echo trans('SampleViewTitle::example.welcome'); | ||
<div> | ||
<!-- To Render translation, create a Lang/{locale}/messages.php file inside module directory --> | ||
<!-- Replace {module} with module name --> | ||
|
||
{{-- {{ __('{module}::messages.welcome') }} --}} | ||
</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