/**
* {control name[:method] [params]}
*/
public function macroControl(MacroNode $node, PhpWriter $writer)
{
$words = $node->tokenizer->fetchWords();
if (!$words) {
throw new CompileException('Missing control name in {control}');
}
$name = $writer->formatWord($words[0]);
$method = isset($words[1]) ? ucfirst($words[1]) : '';
$method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}";
$tokens = $node->tokenizer;
$pos = $tokens->position;
$param = $writer->formatArray();
$tokens->position = $pos;
while ($tokens->nextToken()) {
if ($tokens->isCurrent('=>') && !$tokens->depth) {
$wrap = TRUE;
break;
}
}
if (empty($wrap)) {
$param = substr($param, 1, -1);
// removes array() or []
}
return "/* line {$node->startLine} */ " . ($name[0] === '$' ? "if (is_object({$name})) \$_tmp = {$name}; else " : '') . '$_tmp = $this->global->uiControl->getComponent(' . $name . '); ' . 'if ($_tmp instanceof Nette\\Application\\UI\\IRenderable) $_tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_tmp->{$method}({$param});" : $writer->write("ob_start(function () {}); \$_tmp->{$method}({$param}); echo %modify(ob_get_clean());"));
}