Inheritance: use trait latte\Strict
Example #1
0
 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     $this->used = TRUE;
     $node->empty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
 public function macroLabel(Latte\MacroNode $node, Latte\PhpWriter $writer)
 {
     while ($node->parentNode) {
         if ($node->parentNode->name == 'gpspicker') {
             $cmd = 'if ($_label = $_gpspicker->getPartialLabel(%node.word)) echo $_label->addAttributes(%node.array)';
             if ($node->isEmpty = substr($node->args, -1) === '/') {
                 $node->setArgs(substr($node->args, 0, -1));
                 return $writer->write($cmd);
             } else {
                 return $writer->write($cmd . '->startTag()');
             }
         }
         $node = $node->parentNode;
     }
     throw new CompileException('{gpspicker:label} can be used only within {gpspicker} macro.');
 }
Example #3
0
 /**
  * {status ...}
  */
 public function macroStatus(MacroNode $node, PhpWriter $writer)
 {
     trigger_error('Macro {status} is deprecated.', E_USER_DEPRECATED);
     if ($node->modifiers) {
         throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     return $writer->write((substr($node->args, -1) === '?' ? 'if (!headers_sent()) ' : '') . 'http_response_code(%0.var);', (int) $node->args);
 }
Example #4
0
 /**
  * {inputError ...}
  */
 public function macroInputError(MacroNode $node, PhpWriter $writer)
 {
     if ($node->modifiers) {
         throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     $name = $node->tokenizer->fetchWord();
     $node->replaced = true;
     if (!$name) {
         return $writer->write('echo %escape($_input->getError());');
     } elseif ($name[0] === '$') {
         return $writer->write('$_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo %escape($_input->getError());', $name);
     } else {
         return $writer->write('echo %escape(end($this->global->formsStack)[%0.word]->getError());', $name);
     }
 }
 /**
  * @param \Nette\Latte\MacroNode $node
  * @param \Nette\Latte\PhpWriter $writer
  * @return string
  */
 public function macroFormBegin(MacroNode $node, PhpWriter $writer)
 {
     if ($node->isEmpty = substr($node->args, -1) === '/') {
         $node->setArgs(substr($node->args, 0, -1));
         return $writer->write('$form = $__form = $_form = (is_object(%node.word) ? %node.word : $_control->getComponent(%node.word)); $__form->render(NULL, %node.array);');
     } elseif (($token = $this->findCurrentToken()) && $token->empty) {
         // $node->isEmpty = TRUE;
         return $writer->write('$form = $__form = $_form = (is_object(%node.word) ? %node.word : $_control->getComponent(%node.word)); $__form->render(NULL, %node.array);');
     }
     $word = $node->tokenizer->fetchWord();
     $node->isEmpty = in_array($word, array('errors', 'body', 'controls', 'buttons'));
     $node->tokenizer->reset();
     return $writer->write('$form = $__form = $_form = ' . get_called_class() . '::renderFormPart(%node.word, %node.array, get_defined_vars())');
 }
Example #6
0
 public function texyOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
 }
Example #7
0
 /** @internal */
 protected function checkExtraArgs(MacroNode $node)
 {
     if ($node->tokenizer->isNext()) {
         $args = Latte\Runtime\Filters::truncate($node->tokenizer->joinAll(), 20);
         trigger_error("Unexpected arguments '{$args}' in " . $node->getNotation());
     }
 }
Example #8
0
 /**
  * {ifCurrent destination [,] [params]}
  */
 public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
 {
     if ($node->modifiers) {
         throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     return $writer->write($node->args ? 'if ($this->global->uiPresenter->isLinkCurrent(%node.word, %node.array?)) {' : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {');
 }
Example #9
0
 /**
  * {ifset block}
  * {elseifset block}
  */
 public function macroIfset(MacroNode $node, PhpWriter $writer)
 {
     if ($node->modifiers) {
         throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     if (!preg_match('~#|[\\w-]+\\z~A', $node->args)) {
         return FALSE;
     }
     $list = [];
     while (($name = $node->tokenizer->fetchWord()) !== FALSE) {
         $list[] = preg_match('~#|[\\w-]+\\z~A', $name) ? '$this->blockQueue["' . ltrim($name, '#') . '"]' : $writer->formatArgs(new Latte\MacroTokens($name));
     }
     return ($node->name === 'elseifset' ? '} else' : '') . 'if (isset(' . implode(', ', $list) . ')) {';
 }