Example #1
0
 public function parse(Apishka_Templater_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $name = $stream->expect(Apishka_Templater_Token::NAME_TYPE)->getValue();
     if ($this->parser->hasBlock($name)) {
         throw new Apishka_Templater_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
     }
     $this->parser->setBlock($name, $block = Apishka_Templater_Node_Block::apishka($name, Apishka_Templater_Node::apishka(array()), $lineno));
     $this->parser->pushLocalScope();
     $this->parser->pushBlockStack($name);
     if ($stream->nextIf(Apishka_Templater_Token::BLOCK_END_TYPE)) {
         $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
         if ($token = $stream->nextIf(Apishka_Templater_Token::NAME_TYPE)) {
             $value = $token->getValue();
             if ($value != $name) {
                 throw new Apishka_Templater_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
             }
         }
     } else {
         $body = Apishka_Templater_Node::apishka(array(Apishka_Templater_Node_Print::apishka($this->parser->getExpressionParser()->parseExpression(), $lineno)));
     }
     $stream->expect(Apishka_Templater_Token::BLOCK_END_TYPE);
     $block->setNode('body', $body);
     $this->parser->popBlockStack();
     $this->parser->popLocalScope();
     return Apishka_Templater_Node_BlockReference::apishka($name, $lineno, $this->getTag());
 }
Example #2
0
 public function parse(Apishka_Templater_Token $token)
 {
     $name = $this->parser->getVarName();
     $ref = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka($name, $token->getLine()), Apishka_Templater_Node::apishka(), true, $token->getLine(), $this->getTag());
     $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
     $this->parser->getStream()->expect(Apishka_Templater_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
     $this->parser->getStream()->expect(Apishka_Templater_Token::BLOCK_END_TYPE);
     $block = Apishka_Templater_Node_Block::apishka($name, $body, $token->getLine());
     $this->parser->setBlock($name, $block);
     return Apishka_Templater_Node_Print::apishka($filter, $token->getLine(), $this->getTag());
 }
Example #3
0
    public function getTests()
    {
        $body = Apishka_Templater_Node_Text::apishka('foo', 1);
        $node = Apishka_Templater_Node_Block::apishka('foo', $body, 1);
        return array(array($node, <<<EOF
// line 1
public function block_foo(\$context, array \$blocks = array())
{
    echo "foo";
}
EOF
));
    }
Example #4
0
 public function setBlock($name, Apishka_Templater_Node_Block $value)
 {
     $this->blocks[$name] = Apishka_Templater_Node_Body::apishka(array($value), array(), $value->getLine());
 }