Skip to content

Commit f01021e

Browse files
committed
RoutingPanel: convert templates to Latte-like syntax
1 parent ccf65ad commit f01021e

File tree

7 files changed

+404
-199
lines changed

7 files changed

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

0 commit comments

Comments
 (0)