Compare commits

...

6 Commits

13 changed files with 118 additions and 53 deletions

View File

@ -36,6 +36,16 @@ footer {
margin-top: 1.5rem;
text-align: center;
& dl {
text-align: center;
& > * {
display: inline;
margin-left: 0.5rem;
margin-right: 0.5rem;
}
}
& p {
padding-top: 1rem;
padding-bottom: 1rem;

View File

@ -1,9 +1,6 @@
twig:
file_name_pattern: '*.twig'
default_path: '%kernel.project_dir%/templates'
globals:
app_clock: '@Psr\Clock\ClockInterface'
app_page_title: '@App\Twig\PageTitle'
when@test:
twig:

View File

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Twig;
use App\Service\VersionReader;
use Override;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class AppVersionExtension extends AbstractExtension
{
public function __construct(
private VersionReader $versionReader,
) {}
#[Override]
public function getFunctions(): array
{
return [
new TwigFunction('app_version', [$this, 'getVersion']),
];
}
public function getVersion(): string
{
return ($this->versionReader)();
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace App\Twig;
namespace App\Twig\DTO;
use function array_filter;
use function implode;

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace App\Twig\Extension;
use App\Service\VersionReader;
use App\Twig\DTO\PageTitle;
use DateTimeImmutable;
use Override;
use Psr\Clock\ClockInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class AppExtension extends AbstractExtension
{
private readonly PageTitle $pageTitle;
public function __construct(
private readonly ClockInterface $clock,
private readonly VersionReader $versionReader,
) {
$this->pageTitle = new PageTitle();
}
#[Override]
public function getFunctions(): array
{
return [
new TwigFunction('app_server_time', $this->getServerTime(...)),
new TwigFunction('app_version', $this->getAppVersion(...)),
new TwigFunction('app_page_title', $this->getPageTitle(...)),
new TwigFunction('app_set_page_title_separator', $this->setPageTitleSeparator(...)),
new TwigFunction('app_set_page_title_item', $this->setPageTitleItem(...)),
new TwigFunction('app_set_page_title_page', $this->setPageTitlePage(...)),
new TwigFunction('app_set_page_title_world', $this->setPageTitleWorld(...)),
new TwigFunction('app_set_page_title_root', $this->setPageTitleRoot(...)),
new TwigFunction('app_set_page_title_subtitle', $this->setPageTitleSubtitle(...)),
];
}
public function getServerTime(): DateTimeImmutable
{
return $this->clock->now();
}
public function getAppVersion(): string
{
return ($this->versionReader)();
}
public function getPageTitle(): string
{
return (string) $this->pageTitle;
}
public function setPageTitleSeparator(string $separator): void
{
$this->pageTitle->setSeparator(separator: $separator);
}
public function setPageTitleItem(null | string $item): void
{
$this->pageTitle->setItem($item);
}
public function setPageTitlePage(null | string $page): void
{
$this->pageTitle->setPage(page: $page);
}
public function setPageTitleWorld(null | string $world): void
{
$this->pageTitle->setWorld(world: $world);
}
public function setPageTitleRoot(null | string $root): void
{
$this->pageTitle->setRoot(root: $root);
}
public function setPageTitleSubtitle(null | string $subtitle): void
{
$this->pageTitle->setSubtitle(subtitle: $subtitle);
}
}

View File

@ -1,13 +1,13 @@
{%- block init -%}
{%- do app_page_title.setSeparator(' ') -%} {# U+2013 EN DASH #}
{%- do app_page_title.setRoot('Shintolin') -%}
{%- do app_set_page_title_separator(' ') -%} {# U+2013 EN DASH #}
{%- do app_set_page_title_root('Shintolin') -%}
{%- endblock -%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ app_page_title }}</title>
<title>{{ app_page_title() }}</title>
<link rel="stylesheet" href="{{ asset('vendor/bootstrap/dist/css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/@fontsource/freckle-face/index.min.css') }}">
<link rel="stylesheet" href="{{ asset('css/default.css') }}">
@ -21,16 +21,18 @@
{% block body %}{% endblock %}
{%- set current_datetime = app_clock.now() -%}
{%- set current_datetime = app_server_time() -%}
{%- set current_datetime_machine = current_datetime|date(constant('DATE_ATOM')) -%}
{%- set current_datetime_human = current_datetime|format_datetime(pattern='yyyy-MM-dd, HH:mm:ss z') -%}
<footer>
<p>
<b>Server Time:</b>
<time datetime="{{ current_datetime_machine }}">{{ current_datetime_human }}</time>
<b>Game Engine version:</b>
<code>{{ app_version() }}</code>
</p>
<dl>
<dt>Server Time:</dt>
<dd>
<time datetime="{{ current_datetime_machine }}">{{ current_datetime_human }}</time>
</dd>
<dt>Version:</dt>
<dd><code>{{ app_version() }}</code></dd>
</dl>
</footer>
</body>
</html>

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage('Game') -%}
{%- do app_set_page_title_page('Game') -%}
{%- endblock -%}
{% block body %}

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage('Discord server') -%}
{%- do app_set_page_title_page('Discord server') -%}
{%- endblock -%}
{% block content %}

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage('Frequently Asked Questions') -%}
{%- do app_set_page_title_page('Frequently Asked Questions') -%}
{%- endblock -%}
{% block content %}

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setSubtitle('Explore. Settle. Trade. Conquer.') -%}
{%- do app_set_page_title_subtitle('Explore. Settle. Trade. Conquer.') -%}
{%- endblock -%}
{% block stylesheets -%}

View File

@ -2,9 +2,9 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage(world ? 'Local leaderboard' : 'Global leaderboard') -%}
{%- do app_page_title.setWorld(world) -%}
{%- do app_page_title.setItem(metric) -%}
{%- do app_set_page_title_page(world ? 'Local leaderboard' : 'Global leaderboard') -%}
{%- do app_set_page_title_world(world) -%}
{%- do app_set_page_title_item(metric) -%}
{%- endblock -%}
{% block content %}

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage('Release Notes') -%}
{%- do app_set_page_title_page('Release Notes') -%}
{%- endblock -%}
{% block content %}

View File

@ -2,7 +2,7 @@
{%- block init -%}
{{- parent() -}}
{%- do app_page_title.setPage('State of the Game: July 2015') -%}
{%- do app_set_page_title_page('State of the Game: July 2015') -%}
{%- endblock -%}
{% block content %}