Skip to content

Commit 5be39a3

Browse files
committed
RoutingPanel: convert templates to Latte-like syntax
1 parent 97be91a commit 5be39a3

File tree

7 files changed

+413
-199
lines changed

7 files changed

+413
-199
lines changed

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getTab(): string
4545
);
4646
return Nette\Utils\Helpers::capture(function () {
4747
$matched = $this->matched;
48-
require __DIR__ . '/templates/RoutingPanel.tab.phtml';
48+
require __DIR__ . '/dist/tab.phtml';
4949
});
5050
}
5151

@@ -61,7 +61,7 @@ public function getPanel(): string
6161
$source = $this->matched ? $this->findSource() : null;
6262
$url = $this->httpRequest->getUrl();
6363
$method = $this->httpRequest->getMethod();
64-
require __DIR__ . '/templates/RoutingPanel.panel.phtml';
64+
require __DIR__ . '/dist/panel.phtml';
6565
});
6666
}
6767

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<?php
2+
declare(strict_types=1);
3+
?>
4+
<?php use Nette\Application\UI\Presenter ?>
5+
<?php use Tracy\Dumper ?>
6+
7+
<style class="tracy-debug">
8+
#tracy-debug .nette-RoutingPanel-grid {
9+
background: #FDF5CE;
10+
display: grid;
11+
grid-template-columns: auto 1fr auto auto;
12+
border: 1px solid #E6DFBF;
13+
}
14+
15+
#tracy-debug .nette-RoutingPanel-grid-inner,
16+
#tracy-debug .nette-RoutingPanel-grid-columns {
17+
grid-column: 1 / span 4;
18+
display: grid;
19+
grid-template-columns: subgrid;
20+
}
21+
22+
#tracy-debug .nette-RoutingPanel-grid-columns:nth-child(2n) {
23+
background: rgba(0,0,0,0.02);
24+
}
25+
26+
#tracy-debug .nette-RoutingPanel-grid-header {
27+
color: #655E5E;
28+
background: #F4F3F1;
29+
font-size: 90%;
30+
font-weight: bold;
31+
}
32+
33+
#tracy-debug .nette-RoutingPanel-grid-group-header {
34+
grid-column: 1 / span 4;
35+
font-size: 90%;
36+
font-weight: bold;
37+
text-align: center;
38+
}
39+
40+
#tracy-debug .nette-RoutingPanel-grid-inner .nette-RoutingPanel-grid-inner {
41+
background: #23180007;
42+
box-shadow: 0 1px 20px 0px #00000040;
43+
border-right: 8px solid #0000002e;
44+
}
45+
46+
#tracy-debug .nette-RoutingPanel-grid-columns > div {
47+
border-bottom: 1px solid #95770026;
48+
border-right: 1px solid #95770026;
49+
padding: 2px 5px;
50+
}
51+
52+
#tracy-debug .nette-RoutingPanel-status-yes {
53+
background: #BDE678 !important;
54+
}
55+
56+
#tracy-debug .nette-RoutingPanel-status-may {
57+
background: #C1D3FF !important;
58+
}
59+
60+
#tracy-debug .nette-RoutingPanel-status-error {
61+
background: #ffd2c3 !important;
62+
}
63+
64+
#tracy-debug .nette-RoutingPanel-symbol {
65+
text-align: right;
66+
}
67+
68+
#tracy-debug .nette-RoutingPanel .tracy-dump.tracy-dump {
69+
padding: 0;
70+
margin: 0;
71+
border: none;
72+
}
73+
74+
#tracy-debug .nette-RoutingPanel pre, #tracy-debug .nette-RoutingPanel code {
75+
display: inline;
76+
background: transparent;
77+
}
78+
79+
#tracy-debug .nette-RoutingPanel-rel {
80+
background: #eee;
81+
white-space: nowrap;
82+
}
83+
</style>
84+
85+
<h1>
86+
<?php if ($matched === null): ?>
87+
no route
88+
<?php elseif (isset($matched[Presenter::PresenterKey])): ?>
89+
<?= Tracy\Helpers::escapeHtml($matched[Presenter::PresenterKey]) ?>:<?= Tracy\Helpers::escapeHtml($matched[Presenter::ActionKey] ?? Presenter::DefaultAction) ?>
90+
91+
<?php if (isset($matched[Presenter::SignalKey])): ?> <?= Tracy\Helpers::escapeHtml($matched[Presenter::SignalKey]) ?>!<?php endif ?>
92+
93+
<?php endif ?>
94+
</h1>
95+
96+
<div class="tracy-inner nette-RoutingPanel">
97+
<div class="tracy-inner-container">
98+
<p>
99+
<code><?= Tracy\Helpers::escapeHtml($method) ?></code>
100+
<code><?= Tracy\Helpers::escapeHtml($url->getBaseUrl()) ?><wbr><span class="nette-RoutingPanel-rel"><?= str_replace(['&amp;', '?'], ['<wbr>&amp;', '<wbr>?'], htmlspecialchars($url->getRelativeUrl())) ?></span></code>
101+
</p>
102+
103+
<?php if (is_string($source)): ?>
104+
<p><?= Tracy\Helpers::escapeHtml($source) ?> (class not found)</p>
105+
<?php elseif ($source): ?>
106+
<p><a href="<?= Tracy\Helpers::escapeHtml(Tracy\Helpers::editorUri($source->getFileName(), $source->getStartLine())) ?>"><?= Tracy\Helpers::escapeHtml($source instanceof ReflectionClass ? $source->getName() : $source->getDeclaringClass()->getName() . '::' . $source->getName() . '()') ?></a></p>
107+
<?php endif ?>
108+
</div>
109+
110+
<div class="tracy-inner-container">
111+
<?php if (empty($routes)): ?>
112+
<p>No routes defined.</p>
113+
<?php else: ?>
114+
<div class="nette-RoutingPanel-grid">
115+
<div class="nette-RoutingPanel-grid-columns nette-RoutingPanel-grid-header">
116+
<div></div>
117+
<div>Mask / Class</div>
118+
<div>Defaults</div>
119+
<div>Matched as</div>
120+
</div>
121+
122+
<?php $_blocks['routeList'] = function ($list, $path = '') use (&$_blocks) { ?>
123+
<div class="nette-RoutingPanel-grid-inner">
124+
<?php if ($list['domain'] || $list['module']): ?>
125+
<div class="nette-RoutingPanel-grid-group-header">
126+
<?php if ($list['domain']): ?> domain = <?= Tracy\Helpers::escapeHtml($list['domain']) ?><?php endif ?>
127+
128+
<?php if ($list['module']): ?> module = <?= Tracy\Helpers::escapeHtml($list['module']) ?><?php endif ?>
129+
130+
</div>
131+
<?php endif ?>
132+
<?php $path .= $list['path'] ?>
133+
<?php foreach ($list['routes'] as $router): ?>
134+
<?php if (is_array($router)): ?>
135+
<?php $_blocks['routeList']($router, $path) ?>
136+
<?php else: ?>
137+
<?php $_blocks['route']($router, $path) ?>
138+
<?php endif ?>
139+
<?php endforeach ?>
140+
</div>
141+
<?php } ?>
142+
143+
<?php $_blocks['route'] = function ($route, $path) use (&$_blocks) { ?>
144+
<div class="nette-RoutingPanel-grid-columns nette-RoutingPanel-status-<?= Tracy\Helpers::escapeHtml($route->matched) ?>">
145+
<div class="nette-RoutingPanel-symbol" title="<?= Tracy\Helpers::escapeHtml(['yes' => 'matched as first', 'may' => 'suitable but not matched as first', 'no' => '', 'oneway' => 'one-way', 'error' => 'error'][$route->matched]) ?>">
146+
<?= Tracy\Helpers::escapeHtml(['yes' => '', 'may' => '', 'no' => '', 'oneway' => '', 'error' => ''][$route->matched]) ?>
147+
148+
</div>
149+
150+
<div>
151+
<code title="<?= Tracy\Helpers::escapeHtml($route->class) ?>">
152+
<?php if ($path !== ''): ?> <small><?= Tracy\Helpers::escapeHtml($path) ?></small><?php endif ?>
153+
154+
<?= isset($route->mask) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], htmlspecialchars($route->mask)) : str_replace('\\', '<wbr>\\', htmlspecialchars($route->class)) ?>
155+
156+
</code>
157+
</div>
158+
159+
<div>
160+
<code>
161+
<?php foreach ($route->defaults as $key => $value): ?>
162+
<?= Tracy\Helpers::escapeHtml($key) ?>&nbsp;=&nbsp;<?php if (is_string($value)): ?><?= Tracy\Helpers::escapeHtml($value) ?><br><?= Dumper::toHtml($value, [Dumper::COLLAPSE => true, Dumper::LIVE => true]) ?><?php endif ?>
163+
164+
<?php endforeach ?>
165+
</code>
166+
</div>
167+
168+
<div>
169+
<?php if ($route->params): ?>
170+
<code>
171+
<?php $params = $route->params ?>
172+
<?php if (isset($params[Presenter::PresenterKey])): ?>
173+
<strong><?= Tracy\Helpers::escapeHtml($params['presenter']) ?>:<?= Tracy\Helpers::escapeHtml($params[Presenter::ActionKey] ?? Presenter::DefaultAction) ?></strong>
174+
<br>
175+
<?php unset($params[Presenter::PresenterKey], $params[Presenter::ActionKey]) ?>
176+
<?php endif ?>
177+
<?php foreach ($params as $key => $value): ?>
178+
<?= Tracy\Helpers::escapeHtml($key) ?>&nbsp;=&nbsp;<?php if (is_string($value)): ?><?= Tracy\Helpers::escapeHtml($value) ?><br><?= Dumper::toHtml($value, [Dumper::COLLAPSE => true, Dumper::LIVE => true]) ?><?php endif ?>
179+
180+
<?php endforeach ?>
181+
</code>
182+
<?php elseif ($route->error): ?>
183+
<strong><?= Tracy\Helpers::escapeHtml($route->error->getMessage()) ?></strong>
184+
<?php endif ?>
185+
</div>
186+
</div>
187+
<?php } ?>
188+
189+
<?php $_blocks['routeList']($routes) ?>
190+
</div>
191+
<?php endif ?>
192+
</div>
193+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
declare(strict_types=1);
3+
?>
4+
<?php use Nette\Application\UI\Presenter ?>
5+
6+
<span title="Router">
7+
<svg viewBox="0 0 2048 2048">
8+
<path fill="#d86b01" d="m1559.7 1024c0 17-6 32-19 45l-670 694.48c-13 13-28 19-45 19s-32-6-45-19-19-28-19-45v-306.48h-438.52c-17 0-32-6-45-19s-19-28-19-45v-642c0-17 6-32 19-45s28-19 45-19h438.52v-309.41c0-17 6-32 19-45s28-19 45-19 32 6 45 19l670 691.41c13 13 19 28 19 45z"/>
9+
<path d="m1914.7 1505c0 79-31 147-87 204-56 56-124 85-203 85h-320c-9 0-16-3-22-9-14-23-21-90 3-110 5-4 12-6 21-6h320c44 0 82-16 113-47s47-69 47-113v-962c0-44-16-82-47-113s-69-47-113-47h-312c-11 0-21-3-30-9-15-25-21-90 3-110 5-4 12-6 21-6h320c79 0 147 28 204 85 56 56 82 124 82 204-9 272 9 649 0 954z" fill-opacity=".5" fill="#d86b01"/>
10+
</svg
11+
><span class="tracy-label">
12+
<?php if ($matched === null): ?>
13+
no route
14+
<?php elseif (isset($matched[Presenter::PresenterKey])): ?>
15+
<?= Tracy\Helpers::escapeHtml($matched[Presenter::PresenterKey]) ?>:<?= Tracy\Helpers::escapeHtml($matched[Presenter::ActionKey] ?? Presenter::DefaultAction) ?><?php if (isset($matched[Presenter::SignalKey])): ?>
16+
17+
<?= Tracy\Helpers::escapeHtml($matched[Presenter::SignalKey]) ?>!<?php endif ?>
18+
19+
<?php endif ?>
20+
</span>
21+
</span>

0 commit comments

Comments
 (0)