diff --git a/app/UI/@Templates/@layout.latte b/app/UI/@Templates/@layout.latte new file mode 100644 index 00000000..a8bc4fd1 --- /dev/null +++ b/app/UI/@Templates/@layout.latte @@ -0,0 +1,48 @@ + + + + + + + {block #title|striptags}Webpack Skeleton{/} + + {block #head} + {* This CSS bundle is generated via Webpack. See webpack.config.js *} + + {/block} + + + +
+
+
+

+ Contributte / Webpack Skeleton +

+
+ +
+
+ {$flash->message} +
+
+ +
+ {include #content} +
+ +
+ © {=date(Y)} by @f3l1x +
+
+
+ +{block #scripts} + {* This JS bundle is generated via Webpack. See webpack.config.js *} + +{/block} + + + + + diff --git a/app/UI/Admin/AdminPresenter.php b/app/UI/Admin/AdminPresenter.php new file mode 100644 index 00000000..cae45ba6 --- /dev/null +++ b/app/UI/Admin/AdminPresenter.php @@ -0,0 +1,10 @@ + diff --git a/app/UI/Admin/Templates/default.latte b/app/UI/Admin/Templates/default.latte new file mode 100644 index 00000000..f37acccf --- /dev/null +++ b/app/UI/Admin/Templates/default.latte @@ -0,0 +1,4 @@ +{block #content} +
Go to front →
+ +
This is admin!
diff --git a/app/UI/BasePresenter.php b/app/UI/BasePresenter.php new file mode 100644 index 00000000..ae2bbf71 --- /dev/null +++ b/app/UI/BasePresenter.php @@ -0,0 +1,10 @@ +addText('username', 'Username') ->setRequired('Username is mandatory') - ->setAttribute('placeholder', 'Type your name Mr.?'); + ->setHtmlAttribute('placeholder', 'Type your name Mr.?'); $form->addText('email', 'Email') ->setHtmlAttribute('placeholder', 'Type your e-mail') ->setOption('description', Html::el('span')->setHtml('Try to type cool@nette.org to see validation.')) ->setEmptyValue('@') - ->addFilter(function ($email) { - return Strings::lower($email); - }) + ->addFilter(fn ($email) => Strings::lower($email)) ->addRule($form::REQUIRED, 'E-mail is mandatory') ->addRule($form::EMAIL, 'Given e-mail is not e-mail'); @@ -51,20 +51,22 @@ protected function createComponentUserForm(): Form $form->addSubmit('send', 'OK'); - $form->onValidate[] = function (Form $form) { + $form->onValidate[] = function (Form $form): void { + $values = $form->getUnsafeValues(ArrayHash::class); + // Validate e-mail duplicities (against DB?) - if (Strings::endsWith($form->values->email, '@nette.org')) { - $form->addError(sprintf('E-mail "%s" is already picked', $form->values->email)); + if (str_ends_with($values->email, '@nette.org')) { + $form->addError(sprintf('E-mail "%s" is already picked', $values->email)); } }; - $form->onSubmit[] = function () { + $form->onSubmit[] = function (): void { // This method in invoked always $this->redrawControl('userFormError'); $this->redrawControl('userFormOk'); }; - $form->onSuccess[] = function () { + $form->onSuccess[] = function (): void { // Some handling on success... }; diff --git a/app/UI/Home/Templates/default.latte b/app/UI/Home/Templates/default.latte new file mode 100644 index 00000000..beeab79f --- /dev/null +++ b/app/UI/Home/Templates/default.latte @@ -0,0 +1,68 @@ +{block #content} +
Go to admin →
+ +
Take a look at webpack.config.js.
+ +
+
Snippets
+
RELOAD ALL
+ +
+
+
Box 1 RELOAD
+
Time is: {$datetime|date:'d.m.Y H:i:s'}
+
+
+
Box 2 RELOAD
+
Time is: {$datetime|date:'H:i:s'}
+
+
+
Box 3 RELOAD
+
Time is: {$datetime|date:'U'}
+
+
+
+ +
+
Forms
+
+
+ {snippet userFormOk} + {php $form = $presenter['userForm']} + {if $form->isSuccess()} +
Form OK!
+
{=Tracy\Debugger::dump($form->values, true)|noescape}
+ {/if} + {/snippet} + + {snippet userFormError} + {php $form = $presenter['userForm']} +
+ {$error} +
+ {/snippet} + +
+
+ {label username /} + + + {$form['username']->getOption('description')} +
+
+ {label email /} + + + {$form['email']->getOption('description')} +
+
+ {label age /} + {input age, class => 'mt-1 block w-full'} + + {$form['age']->getOption('description')} +
+ +
+
+
+
diff --git a/app/presenters/AdminPresenter.php b/app/presenters/AdminPresenter.php deleted file mode 100644 index d6730f91..00000000 --- a/app/presenters/AdminPresenter.php +++ /dev/null @@ -1,8 +0,0 @@ -getRequest()?->isMethod(Request::FORWARD)) { - $this->error(); - } - } - - public function renderDefault(BadRequestException $exception): void - { - // load template 403.latte or 404.latte or ... 4xx.latte - $file = __DIR__ . sprintf('/templates/Error/%s.latte', $exception->getCode()); - $file = is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte'; - $this->template->setFile($file); - } - -} diff --git a/app/presenters/ErrorPresenter.php b/app/presenters/ErrorPresenter.php deleted file mode 100644 index fab24fac..00000000 --- a/app/presenters/ErrorPresenter.php +++ /dev/null @@ -1,50 +0,0 @@ -logger = $logger; - } - - public function run(Request $request): Response - { - $e = $request->getParameter('exception'); - - if ($e instanceof BadRequestException) { - // $this->logger->log("HTTP code {$e->getCode()}: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", 'access'); - [$module, , $sep] = Helpers::splitName($request->getPresenterName()); - $errorPresenter = $module . $sep . 'Error4xx'; - return new ForwardResponse($request->setPresenterName($errorPresenter)); - } - - $this->logger->log($e, ILogger::EXCEPTION); - - return new CallbackResponse(function (IRequest $httpRequest, IResponse $httpResponse) { - if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) { - require __DIR__ . '/templates/Error/500.phtml'; - } - }); - } - -} diff --git a/app/presenters/templates/@layout.latte b/app/presenters/templates/@layout.latte deleted file mode 100644 index ab2d262e..00000000 --- a/app/presenters/templates/@layout.latte +++ /dev/null @@ -1,31 +0,0 @@ -{** - * @param string $basePath web base path - * @param array $flashes flash messages - *} - - - - - - {ifset title}{include title|stripHtml} | {/ifset}Nette + Webpack 5 - - - {block #head} - {* This CSS bundle is generated via Webpack. See webpack.config.js *} - - {/block} - - - -
-
{$flash->message}
- - {include #content} -
- -{block #scripts} - {* This JS bundle is generated via Webpack. See webpack.config.js *} - -{/block} - - diff --git a/app/presenters/templates/Admin/default.latte b/app/presenters/templates/Admin/default.latte deleted file mode 100644 index c384f2c0..00000000 --- a/app/presenters/templates/Admin/default.latte +++ /dev/null @@ -1,2 +0,0 @@ -{block #content} -

This is admin

diff --git a/app/presenters/templates/Error/403.latte b/app/presenters/templates/Error/403.latte deleted file mode 100644 index de00328e..00000000 --- a/app/presenters/templates/Error/403.latte +++ /dev/null @@ -1,7 +0,0 @@ -{block content} -

Access Denied

- -

You do not have permission to view this page. Please try contact the web -site administrator if you believe you should be able to view this page.

- -

error 403

diff --git a/app/presenters/templates/Error/404.latte b/app/presenters/templates/Error/404.latte deleted file mode 100644 index 022001c2..00000000 --- a/app/presenters/templates/Error/404.latte +++ /dev/null @@ -1,8 +0,0 @@ -{block content} -

Page Not Found

- -

The page you requested could not be found. It is possible that the address is -incorrect, or that the page no longer exists. Please use a search engine to find -what you are looking for.

- -

error 404

diff --git a/app/presenters/templates/Error/405.latte b/app/presenters/templates/Error/405.latte deleted file mode 100644 index d4248923..00000000 --- a/app/presenters/templates/Error/405.latte +++ /dev/null @@ -1,6 +0,0 @@ -{block content} -

Method Not Allowed

- -

The requested method is not allowed for the URL.

- -

error 405

diff --git a/app/presenters/templates/Error/410.latte b/app/presenters/templates/Error/410.latte deleted file mode 100644 index 99bde92c..00000000 --- a/app/presenters/templates/Error/410.latte +++ /dev/null @@ -1,6 +0,0 @@ -{block content} -

Page Not Found

- -

The page you requested has been taken off the site. We apologize for the inconvenience.

- -

error 410

diff --git a/app/presenters/templates/Error/4xx.latte b/app/presenters/templates/Error/4xx.latte deleted file mode 100644 index d5ce82f1..00000000 --- a/app/presenters/templates/Error/4xx.latte +++ /dev/null @@ -1,4 +0,0 @@ -{block content} -

Oops...

- -

Your browser sent a request that this server could not understand or process.

diff --git a/app/presenters/templates/Error/500.phtml b/app/presenters/templates/Error/500.phtml deleted file mode 100644 index 619611ea..00000000 --- a/app/presenters/templates/Error/500.phtml +++ /dev/null @@ -1,20 +0,0 @@ - - - -Server Error - - - -
-

Server Error

- -

We're sorry! The server encountered an internal error and - was unable to complete your request. Please try again later.

- -

error 500

-
diff --git a/app/presenters/templates/Error/503.phtml b/app/presenters/templates/Error/503.phtml deleted file mode 100644 index 1c2c4273..00000000 --- a/app/presenters/templates/Error/503.phtml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -Site is temporarily down for maintenance - -

We're Sorry

- -

The site is temporarily down for maintenance. Please try again in a few minutes.

diff --git a/app/presenters/templates/Homepage/default.latte b/app/presenters/templates/Homepage/default.latte deleted file mode 100644 index a407cf37..00000000 --- a/app/presenters/templates/Homepage/default.latte +++ /dev/null @@ -1,62 +0,0 @@ -{block #content} -

Nette + Webpack 5

-

Take a look at webpack.config.js.

- -
-

Snippets RELOAD ALL

-
-
-
-

Box 1 RELOAD

- Time is: {$datetime|date:'d.m.Y H:i:s'} -
-
-

Box 2 RELOAD

- Time is: {$datetime|date:'H:i:s'} -
-
-

Box 3 RELOAD

- Time is: {$datetime|date:'U'} -
-
-
- -
-

Form

-
-
- - {snippet userFormOk} - {php $form = $presenter['userForm']} - {if $form->isSuccess()} -
Form OK!
-
{=Tracy\Debugger::dump($form->values, true)|noescape}
- {/if} - {/snippet} - - {snippet userFormError} - {php $form = $presenter['userForm']} -
{$error}
- {/snippet} - -
- {label username /} - - - {$form['username']->getOption('description')} -
-
- {label email /} - - - {$form['email']->getOption('description')} -
-
- {label age /} - {input age, class => 'form-control'} - - {$form['age']->getOption('description')} -
- -
-
diff --git a/app/router/RouterFactory.php b/app/router/RouterFactory.php deleted file mode 100644 index dcc4c2cf..00000000 --- a/app/router/RouterFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -/', 'Homepage:default'); - - return $router; - } - -}