/** * n:input */ public function macroAttrInput(MacroNode $node, PhpWriter $writer) { if ($node->htmlNode->attrs) { $reset = array_fill_keys(array_keys($node->htmlNode->attrs), NULL); return $writer->write('echo $_form[%node.word]->getControl()->addAttributes(%var)->attributes()', $reset); } return $writer->write('echo $_form[%node.word]->getControl()->attributes()'); }
public function templatePrepareFilters($template) { $template->registerFilter($e = new LatteFilter()); $s = new MacroSet($e->compiler); $s->addMacro('helper', 'ob_start()', function ($n) { $w = new PhpWriter($n->tokenizer, $n->args); return $w->write('echo %modify(ob_get_clean())'); }); }
/** * New node is found. * @return bool */ public function nodeOpened(MacroNode $node) { $this->used = TRUE; $node->isEmpty = FALSE; $node->openingCode = PhpWriter::using($node)->write('<?php if (CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Strings::random()); }
/** * {= ...} * {? ...} */ public function macroExpr(MacroNode $node, PhpWriter $writer) { return $writer->write(($node->name === '?' ? '' : 'echo ') . '%modify(%node.args)'); }
/** * Generates code. * @return string */ private function compile(MacroNode $node, $def) { $node->tokenizer->reset(); $writer = PhpWriter::using($node, $this->compiler); if (is_string($def) && substr($def, 0, 1) !== "") { return $writer->write($def); } else { return Callback::create($def)->invoke($node, $writer); } }
/** * {status ...} */ public function macroStatus(MacroNode $node, PhpWriter $writer) { return $writer->write((substr($node->args, -1) === '?' ? 'if (!$netteHttpResponse->isSent()) ' : '') . '$netteHttpResponse->setCode(%var)', (int) $node->args); }