/** * <input n:name> or alias n:input */ public function macroAttrName(NMacroNode $node, NPhpWriter $writer) { if ($node->htmlNode->attrs) { $reset = array_fill_keys(array_keys($node->htmlNode->attrs), NULL); return $writer->write('$_input = (is_object(%node.word) ? %node.word : $_form[%node.word]); echo $_input->getControl()->addAttributes(%var)->attributes()', $reset); } return $writer->write('$_input = (is_object(%node.word) ? %node.word : $_form[%node.word]); echo $_input->getControl()->attributes()'); }
/** * New node is found. * @return bool */ public function nodeOpened(NMacroNode $node) { $this->used = TRUE; $node->isEmpty = FALSE; $node->openingCode = NPhpWriter::using($node) ->write('<?php if (NCacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', NStrings::random() ); }
/** * {includePart "file", name, params} * Alias for get_template_part() */ public function macroIncludePart(NMacroNode $node, NPhpWriter $writer) { $slug = $node->tokenizer->fetchWord(); $params = self::prepareIncludePartParams($writer->formatArray()); $slug = $writer->formatWord($slug); $name = $writer->formatWord($params['name']); return $writer->write('NCoreMacros::includeTemplate(' . __CLASS__ . '::getTemplatePart(' . $slug . ', ' . $name . '), ' . $params['params'] . ' + get_defined_vars(), $_l->templates[%var])->render()', $this->parser->templateId); }
/** * {= ...} * {? ...} */ public function macroExpr(NMacroNode $node, NPhpWriter $writer) { return $writer->write(($node->name === '?' ? '' : 'echo ') . '%modify(%node.args)'); }
/** * Generates code. * @return string */ private function compile(NMacroNode $node, $def) { $node->tokenizer->reset(); $writer = NPhpWriter::using($node, $this->compiler); if (is_string($def)&& substr($def, 0, 1) !== "\0") { return $writer->write($def); } else { return NCallback::create($def)->invoke($node, $writer); } }
/** * {status ...} */ public function macroStatus(NMacroNode $node, NPhpWriter $writer) { return $writer->write((substr($node->args, -1) === '?' ? 'if (!$netteHttpResponse->isSent()) ' : '') . '$netteHttpResponse->setCode(%var)', (int) $node->args ); }
/** * Generates code. * @return string */ private function compile(NMacroNode $node, $def) { $node->tokenizer->reset(); $writer = NPhpWriter::using($node, $this->parser->context); if (is_string($def)&& substr($def, 0, 1) !== "\0") { $code = $writer->write($def); } else { $code = callback($def)->invoke($node, $writer); if ($code === FALSE) { return FALSE; } } return "<?php $code ?>"; }