Browse files

template debugger (not finished)

  • Loading branch information...
1 parent 800513f commit dc6118891220e52e0fd64336d7d1f452a9cde99e @juzna committed Mar 22, 2012
View
5 Nette/Latte/Compiler.php
@@ -26,6 +26,9 @@ class Compiler extends Nette\Object
/** @var string default content type */
public $defaultContentType = self::CONTENT_XHTML;
+ /** @var array */
+ public $templateMetadata;
+
/** @var array of Token */
private $tokens;
@@ -98,7 +101,7 @@ public function addMacro($name, IMacro $macro)
/**
* Compiles tokens to PHP code.
- * @param array
+ * @param Token[] $tokens
* @return string
*/
public function compile(array $tokens)
View
3 Nette/Latte/Engine.php
@@ -49,8 +49,9 @@ public function __construct()
* @param string
* @return string
*/
- public function __invoke($s)
+ public function __invoke($s, $metadata = null)
{
+ $this->compiler->templateMetadata = $metadata;
return $this->compiler->compile($this->parser->parse($s));
}
View
12 Nette/Latte/Macros/UIMacros.php
@@ -103,6 +103,14 @@ public function finalize()
foreach ($this->namedBlocks as $name => $code) {
$func = '_lb' . substr(md5($this->getCompiler()->getTemplateId() . $name), 0, 10) . '_' . preg_replace('#[^a-z0-9_]#i', '_', $name);
$snippet = $name[0] === '_';
+
+ // debug wrapper
+ $func2 = $func . '_wrapper';
+ $prolog[] = "\n"
+ . "if (!function_exists(\$_l->blocks[" . var_export($name, TRUE) . "][] = '$func2')) { "
+ . "function $func2(\$_l, \$_args) { "
+ . "\n?><x-latte-block name=\"$name\" file=\"{$this->getCompiler()->templateMetadata['file']}\"><?php $func(\$_l, \$_args); ?></x-latte-block><?php\n}}";
+
$prolog[] = "//\n// block $name\n//\n"
. "if (!function_exists(\$_l->blocks[" . var_export($name, TRUE) . "][] = '$func')) { "
. "function $func(\$_l, \$_args) { "
@@ -135,6 +143,10 @@ public function finalize()
}';
}
+ // debug wrapper
+/* $prolog[] = "\n?><x-latte-file file=\"{$this->getCompiler()->templateMetadata['file']}\">\n<?php\n";
+ $epilog[] = "\n?></x-latte-file>\n<?php\n";
+*/
return array(implode("\n\n", $prolog), implode("\n", $epilog));
}
View
1 Nette/Templating/FileTemplate.php
@@ -100,6 +100,7 @@ public function render()
$cached = $compiled = $cache->load($this->file);
if ($compiled === NULL) {
+ $this->metadata['file'] = $this->file;
try {
$compiled = "<?php\n\n// source file: $this->file\n\n?>" . $this->compile();
View
5 Nette/Templating/Template.php
@@ -26,6 +26,9 @@ class Template extends Nette\Object implements ITemplate
/** @var array of function(Template $sender); Occurs before a template is compiled - implement to customize the filters */
public $onPrepareFilters = array();
+ /** @var array */
+ public $metadata;
+
/** @var string */
private $source;
@@ -150,7 +153,7 @@ public function compile()
$code = $this->getSource();
foreach ($this->filters as $filter) {
$code = self::extractPhp($code, $blocks);
- $code = $filter/*5.2*->invoke*/($code);
+ $code = $filter/*5.2*->invoke*/($code, $this->metadata);
$code = strtr($code, $blocks); // put PHP code back
}

0 comments on commit dc61188

Please sign in to comment.