Skip to content

Commit

Permalink
feat: Default resource presenters + profile example for user
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-code-labx committed May 11, 2024
1 parent 8125c0b commit 03fa2e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Commands/Generator/MakeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ function (string $presenter, $presenterKey): string {
->plural()
->value();

if ($presenter === 'xtend') {
$presenterPlural = $presenterKey !== 'profile' ? Str::of($presenterKey)->plural()->studly() : 'Users';
$presenterSingle = Str::of($presenterKey)->singular()->studly();

return "'$presenterKey' => \XtendPackages\RESTPresenter\Resources\\$presenterPlural\\Presenters\\$presenterSingle::class";
}

return "'$presenterKey' => Presenters\\".$presenterNamespace.'\\'.$presenter;
},
)->implode(",\n\t\t\t").',';
Expand Down
22 changes: 17 additions & 5 deletions src/Commands/RESTPresenterSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,23 @@ private function publishingDefaultResources(): void
{
collect($this->filesystem->directories(__DIR__.'/../Resources'))
->map(fn ($resource) => Str::singular(basename((string) $resource)))
->each(fn ($resource) => $this->call('rest-presenter:make-resource', [
'model' => 'App\\Models\\'.Str::singular($resource),
'name' => $resource,
'type' => 'new',
]));
->each(function ($resource) {
$resourceKey = Str::of($resource)
->kebab()
->value();

$presenters = [$resourceKey => 'xtend'];
if ($resourceKey === 'user') {
$presenters['profile'] = 'xtend';
}

return $this->call('rest-presenter:make-resource', [
'model' => 'App\\Models\\'.Str::singular($resource),
'presenters' => $presenters,
'name' => $resource,
'type' => 'new',
]);
});
}

private function publishStarterKits(): void
Expand Down

0 comments on commit 03fa2e1

Please sign in to comment.