Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Templates debugger: actual rendered html output is displayed in tree …
…also
  • Loading branch information
jasir committed Feb 22, 2017
1 parent aca1e11 commit 25b22e0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/ComponentTreePanel.php
Expand Up @@ -313,6 +313,7 @@ static public function dumpToHtml($object)

/**
* @param $object
*
* @return mixed
*/
public static function getReflection($object)
Expand Down
10 changes: 10 additions & 0 deletions src/ComponentTreePanelExtension.php
Expand Up @@ -7,6 +7,16 @@

class ComponentTreePanelExtension extends CompilerExtension
{
/**
* Adjusts DI container before is compiled to PHP class. Intended to be overridden by descendant.
* @return void
*/
public function beforeCompile()
{
parent::beforeCompile();
}


/**
* Adjusts DI container compiled to PHP class. Intended to be overridden by descendant.
* @param ClassType $class
Expand Down
28 changes: 14 additions & 14 deletions src/DebugTemplate.php
Expand Up @@ -69,28 +69,28 @@ public function getLatte()
*/
public function render($file = null, array $params = [])
{
ob_start();
$this->template->render($file, $params);
$content = ob_get_contents();
ob_end_clean();

if (count(static::$onRender)) {
foreach (static::$onRender as $callback) {
/** @noinspection PhpUndefinedFieldInspection */
$content = $callback($this->template, $content, $this->template->control !== $this->template->presenter);
}
}
if (!array_key_exists($this->template->getFile(), self::$templatesRendered)) {
self::$templatesRendered[] = [
'template' => $this->template,
'params' => $this->template->getParameters(),
'file' => $this->template->getFile(),
'trace' => debug_backtrace()
'trace' => debug_backtrace(),
'rendered' => $content,
];
}

if (count(static::$onRender)) {
ob_start();
$this->template->render($file, $params);
$content = ob_get_contents();
ob_end_clean();
foreach (static::$onRender as $callback) {
/** @noinspection PhpUndefinedFieldInspection */
$content = $callback($this->template, $content, $this->template->control !== $this->template->presenter);
}
echo $content;
return;
}
$this->template->render($file, $params);
echo $content;
}


Expand Down
11 changes: 8 additions & 3 deletions src/blocks.latte
Expand Up @@ -11,14 +11,19 @@
<ul class="tracy-collapsed">
<li><i>instance of </i>{include #editlink title=>get_class($t), file=>($helpers->getReflection($t))->getFileName()}
{include #dump object => $t}
{php ksort($parameters)}
<li>{include #values values => $parameters, title=>'Parameters', open=>false}</li>
{if $showSources}
<li>Source code {include #toggler}
<pre class="tracy-collapsed source">
{=file_get_contents($t->getFile())}
</pre>
{/if}
{php ksort($parameters)}
<li>{include #values values => $parameters, title=>'Parameters', open=>false}
<li>Rendered {include #toggler}
<pre class="tracy-collapsed source">
{$rendered}
</pre>
</li>
</ul>
{/define}

Expand All @@ -43,7 +48,7 @@
{if !(\Nette\Utils\Strings::startsWith($name, '_') || in_array($name, $omittedVariables))}
<tr><th>{$name}</th><td width="80%"><div class="ct-values">{= \jasir\ComponentTreePanel::dumpToHtmlCached($value) |noescape}</div></td></tr>
{else}
<tr><th>{$name}</th><td><i>{if is_object($value)}{get_class($value) |noescape} - not dumped{else}{= \jasir\ComponentTreePanel::dumpToHtmlCached($value) |noescape}{/if}</i></td></tr>
<tr><th>{$name}</th><td><i>{if is_object($value)}{get_class($value) |noescape} - dump skipped{else}{= \jasir\ComponentTreePanel::dumpToHtmlCached($value) |noescape}{/if}</i></td></tr>
{/if}
{/foreach}
</table>
Expand Down
2 changes: 1 addition & 1 deletion src/component.latte
Expand Up @@ -94,7 +94,7 @@
<li>Templates (rendered) ({count($templates)}){include #toggler}
<ul>
{foreach $templates as $tinfo}
<li>{include #template t=>$tinfo['template'], file => $tinfo['file'], parameters =>$tinfo['params']}
<li>{include #template t=>$tinfo['template'], file => $tinfo['file'], parameters =>$tinfo['params'], rendered => $tinfo['rendered']}
{/foreach}
</ul>
{/if}
Expand Down

0 comments on commit 25b22e0

Please sign in to comment.