Skip to content

Commit

Permalink
LattePanel: convert templates to Latte-like syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 12, 2025
1 parent 5a1571e commit 1c24ac7
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/Tracy/LattePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getTab(): ?string

return Tracy\Helpers::capture(function () {
$name = $this->name ?? basename(reset($this->templates)->getName());
require __DIR__ . '/templates/LattePanel.tab.phtml';
require __DIR__ . '/dist/tab.phtml';
});
}

Expand All @@ -93,7 +93,7 @@ public function getPanel(): string
return Tracy\Helpers::capture(function () {
$list = $this->list;
$dumpParameters = $this->dumpParameters;
require __DIR__ . '/templates/LattePanel.panel.phtml';
require __DIR__ . '/dist/panel.phtml';
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?php
declare(strict_types=1);

namespace Latte\Bridges\Tracy;

use Latte\Runtime\Template;
use Tracy\Dumper;
use Tracy\Helpers;

$colors = [
?>
<?php $colors = [
'include' => '#00000052',
'extends' => '#cd1c1c7d',
'import' => '#17c35b8f',
'includeblock' => '#17c35b8f',
'embed' => '#4f1ccd7d',
'sandbox' => 'black',
];
] ?>

?>

<style class="tracy-debug">
#tracy-debug .LattePanel td {
Expand Down Expand Up @@ -70,32 +63,36 @@ $colors = [

<div class="tracy-inner LattePanel">
<table>
<?php foreach ($list as $item): ?>
<?php foreach ($list as $item): ?>
<tr>
<td>
<?php if ($item->template->getReferenceType()): ?>
<span style="margin-left: <?= $item->depth * 4 ?>ex"></span>└ 
<span class="LattePanel-type" style="background: <?= $colors[$item->template->getReferenceType()] ?>"><?= Helpers::escapeHtml($item->template->getReferenceType()) ?></span>
<?php endif ?>
<?php if ($item->template->getReferenceType()): ?>
<span style="margin-left: <?= Tracy\Helpers::escapeHtml($item->depth * 4) ?>ex"></span>└ 
<span class="LattePanel-type" style="background: <?= Tracy\Helpers::escapeHtml($colors[$item->template->getReferenceType()]) ?>"><?= Tracy\Helpers::escapeHtml($item->template->getReferenceType()) ?></span>
<?php endif ?>

<?= Tracy\Helpers::editorLink($item->template->getName()) ?>

<?= Helpers::editorLink($item->template->getName()) ?>

<a href="<?= Helpers::escapeHtml(Helpers::editorUri($item->phpFile)) ?>" class="LattePanel-php">php</a>
<a href="<?= Tracy\Helpers::escapeHtml(Tracy\Helpers::editorUri($item->phpFile)) ?>" class="LattePanel-php">php</a>
</td>

<td><?= $item->count > 1 ? $item->count . '×' : '' ?></td>
<td><?= Tracy\Helpers::escapeHtml($item->count > 1 ? $item->count . '×' : '') ?></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
</table>

<?php if ($dumpParameters): ?>
<h2>Parameters</h2>

<div class="tracy-inner">
<table class="tracy-sortable tracy-dump-seamless">
<?php foreach (reset($list)->template->getParameters() as $k => $v): ?>
<tr><th><?= Helpers::escapeHtml($k) ?></th><td><?= Dumper::toHtml($v, [Dumper::LIVE => true]) ?></td></tr>
<?php endforeach ?>
</div>
<?php endif ?>
<?php if ($dumpParameters): ?>
<h2>Parameters</h2>

<div class="tracy-inner">
<table class="tracy-sortable">
<?php foreach (reset($list)->template->getParameters() as $k => $v): ?>
<tr>
<th><?= Tracy\Helpers::escapeHtml($k) ?></th>
<td><?= Tracy\Dumper::toHtml($v, [Tracy\Dumper::LIVE => true]) ?></td>
</tr>
<?php endforeach ?>
</table>
</div>
<?php endif ?>
</div>
11 changes: 11 additions & 0 deletions src/Bridges/Tracy/dist/tab.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
?>
<span title="Latte Templates">
<svg viewBox="0 0 1793.77 1538.57">
<path fill="#F1A443" d="M934.87 1166.46c41.84,-2.2 75.14,-17.07 99.91,-44.59 24.77,-27.53 37.16,-58.9 37.16,-94.13 0,-38.53 -12.38,-71.01 -37.16,-97.43 -24.77,-26.42 -58.08,-45.14 -99.91,-56.15l0 292.31zm-67.71 -786.08c-40.74,2.2 -72.66,15.41 -95.79,39.63 -23.12,24.22 -34.68,52.29 -34.68,84.22 0,33.03 11.29,63.03 33.86,90 22.57,26.98 54.77,43.21 96.61,48.72l0 -262.58zm0 1013.98l0 -64.41c-61.66,-5.5 -114.22,-15.97 -157.71,-31.38 -43.49,-15.41 -79.27,-37.43 -107.34,-66.06 -28.07,-28.63 -48.72,-64.13 -61.93,-106.52 -13.21,-42.39 -19.82,-92.76 -19.82,-151.11l198.18 0c4.4,35.23 10.18,64.41 17.34,87.53 7.16,23.12 16.51,41.84 28.07,56.15 11.56,14.31 25.6,25.05 42.11,32.2 16.51,7.16 36.88,12.39 61.1,15.69l0 -318.73c-55.05,-14.31 -102.94,-30.55 -143.67,-48.72 -40.74,-18.16 -74.59,-39.63 -101.57,-64.41 -26.97,-24.77 -47.34,-53.4 -61.1,-85.88 -13.76,-32.48 -20.64,-71.29 -20.64,-116.43 0,-42.93 8.26,-83.39 24.77,-121.38 16.51,-37.98 39.36,-71.29 68.53,-99.91 29.18,-28.63 63.58,-51.19 103.22,-67.71 39.63,-16.51 83.12,-25.32 130.46,-26.42l0 -72.67 67.71 0 0 72.67c203.68,6.6 310.47,113.4 320.38,320.38l-194.87 0c-5.5,-59.45 -18.44,-99.91 -38.81,-121.38 -20.37,-21.47 -49.27,-33.31 -86.7,-35.51l0 284.05c73.76,24.22 132.94,47.89 177.53,71.01 44.59,23.12 78.72,47.61 102.39,73.49 23.67,25.87 39.36,54.22 47.07,85.05 7.71,30.83 11.56,66.61 11.56,107.34 0,48.44 -7.98,92.2 -23.94,131.29 -15.97,39.08 -38.81,72.94 -68.54,101.56 -29.72,28.63 -65.5,51.2 -107.34,67.71 -41.84,16.51 -88.08,25.87 -138.72,28.07l0 64.41 -67.71 0z"/>
<path fill="#5F4D36" d="M462.33 1411.31c-54.32,0 -98.33,-4.78 -132.03,-14.33 -33.7,-9.56 -59.85,-24.14 -78.46,-43.76 -18.61,-19.62 -30.93,-44.51 -36.97,-74.69 -6.04,-30.18 -9.05,-65.38 -9.05,-105.62 0,-9.05 0.5,-22.13 1.51,-39.23 1.01,-17.1 1.76,-35.21 2.27,-54.32 0.5,-19.11 1.26,-36.97 2.26,-53.56 1.01,-16.6 1.51,-28.42 1.51,-35.46 0,-58.34 -8.8,-99.08 -26.41,-122.22 -17.6,-23.13 -50.05,-34.7 -97.33,-34.7l0 -129.76c47.28,0 79.72,-11.82 97.33,-35.46 17.6,-23.64 26.41,-64.63 26.41,-122.97 0,-7.04 -0.5,-18.86 -1.51,-35.46 -1.01,-16.6 -1.76,-33.95 -2.26,-52.06 -0.5,-18.11 -1.26,-35.71 -2.27,-52.81 -1.01,-17.1 -1.51,-30.18 -1.51,-39.23 0,-40.24 3.02,-75.45 9.05,-105.62 6.03,-30.18 18.36,-55.08 36.97,-74.69 18.61,-19.62 44.76,-34.2 78.46,-43.76 33.7,-9.56 77.71,-14.34 132.03,-14.34l55.83 0 0 123.73 -33.2 0c-44.26,0 -74.18,7.04 -89.78,21.12 -15.59,14.08 -23.39,38.73 -23.39,73.94 0,45.27 1.51,90.03 4.53,134.29 3.02,44.26 4.53,89.02 4.53,134.29 0,21.12 -4.53,40.49 -13.58,58.09 -9.05,17.6 -20.87,33.19 -35.46,46.77 -14.59,13.58 -31.69,24.4 -51.3,32.44 -19.62,8.05 -39.98,13.58 -61.11,16.6 21.12,3.02 41.49,8.55 61.11,16.59 19.61,8.05 36.72,18.86 51.3,32.44 14.59,13.58 26.41,29.17 35.46,46.77 9.05,17.6 13.58,36.97 13.58,58.09 0,45.27 -1.51,90.28 -4.53,135.04 -3.02,44.76 -4.53,89.78 -4.53,135.05 0,35.21 7.79,59.85 23.39,73.94 15.59,14.08 45.52,21.12 89.78,21.12l33.2 0 0 123.73 -55.83 0z"/>
<path fill="#5F4D36" d="M1275.61 1411.31l0 -123.73 33.2 0c44.26,0 74.19,-7.04 89.78,-21.12 15.59,-14.08 23.39,-38.73 23.39,-73.94 0,-45.27 -1.51,-90.28 -4.53,-135.05 -3.02,-44.76 -4.53,-89.78 -4.53,-135.04 0,-21.12 4.53,-40.49 13.58,-58.09 9.05,-17.6 20.87,-33.19 35.46,-46.77 14.59,-13.58 31.69,-24.4 51.3,-32.44 19.61,-8.05 39.98,-13.58 61.11,-16.59 -21.12,-3.02 -41.5,-8.55 -61.11,-16.6 -19.62,-8.05 -36.72,-18.86 -51.3,-32.44 -14.59,-13.58 -26.41,-29.17 -35.46,-46.77 -9.05,-17.6 -13.58,-36.97 -13.58,-58.09 0,-45.27 1.51,-90.03 4.53,-134.29 3.02,-44.26 4.53,-89.02 4.53,-134.29 0,-35.21 -7.8,-59.85 -23.39,-73.94 -15.59,-14.08 -45.52,-21.12 -89.78,-21.12l-33.2 0 0 -123.73 55.83 0c54.32,0 98.33,4.78 132.03,14.34 33.7,9.55 59.85,24.14 78.46,43.76 18.61,19.61 30.93,44.51 36.97,74.69 6.03,30.17 9.05,65.38 9.05,105.62 0,9.05 -0.5,22.13 -1.51,39.23 -1.01,17.1 -1.76,34.7 -2.26,52.81 -0.5,18.11 -1.26,35.46 -2.27,52.06 -1.01,16.59 -1.51,28.41 -1.51,35.46 0,58.34 8.8,99.33 26.41,122.97 17.6,23.64 50.04,35.46 97.32,35.46l0 129.76c-47.28,0 -79.72,11.57 -97.32,34.7 -17.6,23.14 -26.41,63.88 -26.41,122.22 0,7.04 0.5,18.86 1.51,35.46 1.01,16.6 1.76,34.45 2.27,53.56 0.5,19.11 1.26,37.22 2.26,54.32 1.01,17.1 1.51,30.18 1.51,39.23 0,40.24 -3.02,75.44 -9.05,105.62 -6.04,30.18 -18.36,55.07 -36.97,74.69 -18.61,19.61 -44.76,34.2 -78.46,43.76 -33.7,9.55 -77.7,14.33 -132.03,14.33l-55.83 0z"/>
</svg
><span class="tracy-label"><?= Tracy\Helpers::escapeHtml($name) ?></span>
</span>
94 changes: 94 additions & 0 deletions src/Bridges/Tracy/panel.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{do $colors = [
'include' => '#00000052',
'extends' => '#cd1c1c7d',
'import' => '#17c35b8f',
'includeblock' => '#17c35b8f',
'embed' => '#4f1ccd7d',
'sandbox' => 'black',
]}

<style class="tracy-debug">
#tracy-debug .LattePanel td {
white-space: nowrap;
}
#tracy-debug .LattePanel-php {
background: #8993be;
color: white;
border-radius: 79px;
padding: 1px 4px 3px 4px;
font-size: 75%;
font-style: italic;
font-weight: bold;
vertical-align: text-top;
opacity: .5;
margin-left: 2ex;
}
#tracy-debug .LattePanel-type {
border-radius: 2px;
padding: 2px 4px;
font-size: 80%;
color: white;
font-weight: bold;
}
#tracy-debug .LattePanel-include {
background: #00000052;
}
#tracy-debug .LattePanel-extends {
background: #cd1c1c7d;
}
#tracy-debug .LattePanel-import,
#tracy-debug .LattePanel-includeblock {
background: #17c35b8f;
}
#tracy-debug .LattePanel-embed {
background: #4f1ccd7d;
}
#tracy-debug .LattePanel-sandbox {
background: black;
}
</style>

<h1>Rendered Templates</h1>

<div class="tracy-inner LattePanel">
<table>
{foreach $list as $item}
<tr>
<td>
{if $item->template->getReferenceType()}
<span style="margin-left: {$item->depth * 4}ex"></span>└ 
<span class="LattePanel-type" style="background: {$colors[$item->template->getReferenceType()]}">{$item->template->getReferenceType()}</span>
{/if}

{Tracy\Helpers::editorLink($item->template->getName())}

<a href="{Tracy\Helpers::editorUri($item->phpFile)}" class="LattePanel-php">php</a>
</td>

<td>{$item->count > 1 ? $item->count . '×' : ''}</td>
</tr>
{/foreach}
</table>

{if $dumpParameters}
<h2>Parameters</h2>

<div class="tracy-inner">
<table class="tracy-sortable">
{foreach reset($list)->template->getParameters() as $k => $v}
<tr>
<th>{$k}</th>
<td>{Tracy\Dumper::toHtml($v, [Tracy\Dumper::LIVE => true])}</td>
</tr>
{/foreach}
</table>
</div>
{/if}
</div>
8 changes: 8 additions & 0 deletions src/Bridges/Tracy/tab.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span title="Latte Templates">
<svg viewBox="0 0 1793.77 1538.57">
<path fill="#F1A443" d="M934.87 1166.46c41.84,-2.2 75.14,-17.07 99.91,-44.59 24.77,-27.53 37.16,-58.9 37.16,-94.13 0,-38.53 -12.38,-71.01 -37.16,-97.43 -24.77,-26.42 -58.08,-45.14 -99.91,-56.15l0 292.31zm-67.71 -786.08c-40.74,2.2 -72.66,15.41 -95.79,39.63 -23.12,24.22 -34.68,52.29 -34.68,84.22 0,33.03 11.29,63.03 33.86,90 22.57,26.98 54.77,43.21 96.61,48.72l0 -262.58zm0 1013.98l0 -64.41c-61.66,-5.5 -114.22,-15.97 -157.71,-31.38 -43.49,-15.41 -79.27,-37.43 -107.34,-66.06 -28.07,-28.63 -48.72,-64.13 -61.93,-106.52 -13.21,-42.39 -19.82,-92.76 -19.82,-151.11l198.18 0c4.4,35.23 10.18,64.41 17.34,87.53 7.16,23.12 16.51,41.84 28.07,56.15 11.56,14.31 25.6,25.05 42.11,32.2 16.51,7.16 36.88,12.39 61.1,15.69l0 -318.73c-55.05,-14.31 -102.94,-30.55 -143.67,-48.72 -40.74,-18.16 -74.59,-39.63 -101.57,-64.41 -26.97,-24.77 -47.34,-53.4 -61.1,-85.88 -13.76,-32.48 -20.64,-71.29 -20.64,-116.43 0,-42.93 8.26,-83.39 24.77,-121.38 16.51,-37.98 39.36,-71.29 68.53,-99.91 29.18,-28.63 63.58,-51.19 103.22,-67.71 39.63,-16.51 83.12,-25.32 130.46,-26.42l0 -72.67 67.71 0 0 72.67c203.68,6.6 310.47,113.4 320.38,320.38l-194.87 0c-5.5,-59.45 -18.44,-99.91 -38.81,-121.38 -20.37,-21.47 -49.27,-33.31 -86.7,-35.51l0 284.05c73.76,24.22 132.94,47.89 177.53,71.01 44.59,23.12 78.72,47.61 102.39,73.49 23.67,25.87 39.36,54.22 47.07,85.05 7.71,30.83 11.56,66.61 11.56,107.34 0,48.44 -7.98,92.2 -23.94,131.29 -15.97,39.08 -38.81,72.94 -68.54,101.56 -29.72,28.63 -65.5,51.2 -107.34,67.71 -41.84,16.51 -88.08,25.87 -138.72,28.07l0 64.41 -67.71 0z"/>
<path fill="#5F4D36" d="M462.33 1411.31c-54.32,0 -98.33,-4.78 -132.03,-14.33 -33.7,-9.56 -59.85,-24.14 -78.46,-43.76 -18.61,-19.62 -30.93,-44.51 -36.97,-74.69 -6.04,-30.18 -9.05,-65.38 -9.05,-105.62 0,-9.05 0.5,-22.13 1.51,-39.23 1.01,-17.1 1.76,-35.21 2.27,-54.32 0.5,-19.11 1.26,-36.97 2.26,-53.56 1.01,-16.6 1.51,-28.42 1.51,-35.46 0,-58.34 -8.8,-99.08 -26.41,-122.22 -17.6,-23.13 -50.05,-34.7 -97.33,-34.7l0 -129.76c47.28,0 79.72,-11.82 97.33,-35.46 17.6,-23.64 26.41,-64.63 26.41,-122.97 0,-7.04 -0.5,-18.86 -1.51,-35.46 -1.01,-16.6 -1.76,-33.95 -2.26,-52.06 -0.5,-18.11 -1.26,-35.71 -2.27,-52.81 -1.01,-17.1 -1.51,-30.18 -1.51,-39.23 0,-40.24 3.02,-75.45 9.05,-105.62 6.03,-30.18 18.36,-55.08 36.97,-74.69 18.61,-19.62 44.76,-34.2 78.46,-43.76 33.7,-9.56 77.71,-14.34 132.03,-14.34l55.83 0 0 123.73 -33.2 0c-44.26,0 -74.18,7.04 -89.78,21.12 -15.59,14.08 -23.39,38.73 -23.39,73.94 0,45.27 1.51,90.03 4.53,134.29 3.02,44.26 4.53,89.02 4.53,134.29 0,21.12 -4.53,40.49 -13.58,58.09 -9.05,17.6 -20.87,33.19 -35.46,46.77 -14.59,13.58 -31.69,24.4 -51.3,32.44 -19.62,8.05 -39.98,13.58 -61.11,16.6 21.12,3.02 41.49,8.55 61.11,16.59 19.61,8.05 36.72,18.86 51.3,32.44 14.59,13.58 26.41,29.17 35.46,46.77 9.05,17.6 13.58,36.97 13.58,58.09 0,45.27 -1.51,90.28 -4.53,135.04 -3.02,44.76 -4.53,89.78 -4.53,135.05 0,35.21 7.79,59.85 23.39,73.94 15.59,14.08 45.52,21.12 89.78,21.12l33.2 0 0 123.73 -55.83 0z"/>
<path fill="#5F4D36" d="M1275.61 1411.31l0 -123.73 33.2 0c44.26,0 74.19,-7.04 89.78,-21.12 15.59,-14.08 23.39,-38.73 23.39,-73.94 0,-45.27 -1.51,-90.28 -4.53,-135.05 -3.02,-44.76 -4.53,-89.78 -4.53,-135.04 0,-21.12 4.53,-40.49 13.58,-58.09 9.05,-17.6 20.87,-33.19 35.46,-46.77 14.59,-13.58 31.69,-24.4 51.3,-32.44 19.61,-8.05 39.98,-13.58 61.11,-16.59 -21.12,-3.02 -41.5,-8.55 -61.11,-16.6 -19.62,-8.05 -36.72,-18.86 -51.3,-32.44 -14.59,-13.58 -26.41,-29.17 -35.46,-46.77 -9.05,-17.6 -13.58,-36.97 -13.58,-58.09 0,-45.27 1.51,-90.03 4.53,-134.29 3.02,-44.26 4.53,-89.02 4.53,-134.29 0,-35.21 -7.8,-59.85 -23.39,-73.94 -15.59,-14.08 -45.52,-21.12 -89.78,-21.12l-33.2 0 0 -123.73 55.83 0c54.32,0 98.33,4.78 132.03,14.34 33.7,9.55 59.85,24.14 78.46,43.76 18.61,19.61 30.93,44.51 36.97,74.69 6.03,30.17 9.05,65.38 9.05,105.62 0,9.05 -0.5,22.13 -1.51,39.23 -1.01,17.1 -1.76,34.7 -2.26,52.81 -0.5,18.11 -1.26,35.46 -2.27,52.06 -1.01,16.59 -1.51,28.41 -1.51,35.46 0,58.34 8.8,99.33 26.41,122.97 17.6,23.64 50.04,35.46 97.32,35.46l0 129.76c-47.28,0 -79.72,11.57 -97.32,34.7 -17.6,23.14 -26.41,63.88 -26.41,122.22 0,7.04 0.5,18.86 1.51,35.46 1.01,16.6 1.76,34.45 2.27,53.56 0.5,19.11 1.26,37.22 2.26,54.32 1.01,17.1 1.51,30.18 1.51,39.23 0,40.24 -3.02,75.44 -9.05,105.62 -6.04,30.18 -18.36,55.07 -36.97,74.69 -18.61,19.61 -44.76,34.2 -78.46,43.76 -33.7,9.55 -77.7,14.33 -132.03,14.33l-55.83 0z"/>
</svg
><span class="tracy-label">{$name}</span>
</span>
15 changes: 0 additions & 15 deletions src/Bridges/Tracy/templates/LattePanel.tab.phtml

This file was deleted.

0 comments on commit 1c24ac7

Please sign in to comment.