Skip to content

Instantly share code, notes, and snippets.

@achtan
Created December 12, 2012 12:09
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save achtan/4267298 to your computer and use it in GitHub Desktop.
<?php
use Nette\Latte\Compiler;
use Nette\Latte\MacroNode;
use Nette\Latte\PhpWriter;
class Macros extends \Nette\Latte\Macros\MacroSet {
public static function install(Compiler $compiler) {
$me = parent::install($compiler);
$me->addMacro('timer', array($me, 'macroTimer'), '\Nette\Diagnostics\Debugger::barDump(\Nette\Diagnostics\Debugger::timer(%node.word), %node.word)');
return $me;
}
public function macroTimer(MacroNode $node, PhpWriter $writer)
{
$cmd = '\Nette\Diagnostics\Debugger::timer(%node.word)';
if ($node->isEmpty = (substr($node->args, -1) === '/')) {
$cmd = '\Nette\Diagnostics\Debugger::barDump(' . $cmd . ', %node.word)';
return $writer->write($cmd);
} else {
return $writer->write($cmd);
}
}
}
{timer 'foo' /}
{timer 'foo' /}
{timer 'bar'}{/timer}
<div n:timer="baz"></div>
@jasir
Copy link

jasir commented Apr 9, 2013

Nechceš z toho zkusit udělat pull request do Nette?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment