Example #1
0
	/**
	 * <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()');
	}
Example #2
0
	/**
	 * 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()
			);
	}
Example #3
0
 /**
  * {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);
 }
Example #4
0
	/**
	 * {= ...}
	 * {? ...}
	 */
	public function macroExpr(NMacroNode $node, NPhpWriter $writer)
	{
		return $writer->write(($node->name === '?' ? '' : 'echo ') . '%modify(%node.args)');
	}
Example #5
0
	/**
	 * 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);
		}
	}
Example #6
0
	/**
	 * {status ...}
	 */
	public function macroStatus(NMacroNode $node, NPhpWriter $writer)
	{
		return $writer->write((substr($node->args, -1) === '?' ? 'if (!$netteHttpResponse->isSent()) ' : '') .
			'$netteHttpResponse->setCode(%var)', (int) $node->args
		);
	}
Example #7
0
	/**
	 * 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 ?>";
	}