-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #1107 [Site] Isolate packages/demo structure (smnandre)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Site] Isolate packages/demo structure | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | License | MIT Rework a bit the folder structure / URLs to enforce separation of demos & ux packages * controllers * templates * assets (+ some minor CS fixes) Commits ------- fb738b8 [Site] Isolate packages/demo structure
- Loading branch information
Showing
117 changed files
with
871 additions
and
527 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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
controllers: | ||
resource: ../src/Controller/ | ||
type: annotation | ||
type: attribute | ||
|
||
kernel: | ||
resource: ../src/Kernel.php | ||
|
Empty file.
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,19 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Service\LiveDemoRepository; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class DemosController extends AbstractController | ||
{ | ||
#[Route('/demos', name: 'app_demos')] | ||
public function __invoke(LiveDemoRepository $liveDemoRepository): Response | ||
{ | ||
return $this->render('main/demos.html.twig', [ | ||
'liveComponentDemos' => $liveDemoRepository->findAll(), | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
73 changes: 73 additions & 0 deletions
73
ux.symfony.com/src/Controller/UxPackage/AutocompleteController.php
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,73 @@ | ||
<?php | ||
|
||
namespace App\Controller\UxPackage; | ||
|
||
use App\Entity\Food; | ||
use App\Form\TimeForAMealForm; | ||
use App\Service\UxPackageRepository; | ||
use Doctrine\Common\Collections\Collection; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class AutocompleteController extends AbstractController | ||
{ | ||
#[Route('/autocomplete', name: 'app_autocomplete')] | ||
public function __invoke(UxPackageRepository $packageRepository, Request $request): Response | ||
{ | ||
$package = $packageRepository->find('autocomplete'); | ||
|
||
$form = $this->createForm(TimeForAMealForm::class); | ||
|
||
$form->handleRequest($request); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
$data = $form->getData(); | ||
|
||
$this->addFlash( | ||
'autocomplete_success', | ||
$this->generateEatingMessage( | ||
$data['foods'], | ||
$data['name'] | ||
) | ||
); | ||
|
||
return $this->redirectToRoute('app_autocomplete'); | ||
} | ||
|
||
return $this->render('ux_packages/autocomplete.html.twig', [ | ||
'package' => $package, | ||
'form' => $form, | ||
]); | ||
} | ||
|
||
private function getDeliciousWord(): string | ||
{ | ||
$words = ['delicious', 'scrumptious', 'mouth-watering', 'life-changing', 'world-beating', 'freshly-squeezed']; | ||
|
||
return $words[array_rand($words)]; | ||
} | ||
|
||
private function generateEatingMessage(Collection $foods, string $name): string | ||
{ | ||
$i = 0; | ||
$foodStrings = $foods->map(function (Food $food) use (&$i, $foods) { | ||
++$i; | ||
$str = $food->getName(); | ||
|
||
if ($i === \count($foods) && $i > 1) { | ||
$str = 'and '.$str; | ||
} | ||
|
||
return $str; | ||
}); | ||
|
||
return sprintf( | ||
'Time for %s! Enjoy %s %s %s!', | ||
$name, | ||
\count($foodStrings) > 1 ? 'some' : 'a', | ||
$this->getDeliciousWord(), | ||
implode(\count($foodStrings) > 2 ? ', ' : ' ', $foodStrings->toArray()) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.