Пример #1
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());
 }
Пример #2
0
    public function getTests()
    {
        $tests = array();
        // render: no args
        $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(), false, 1);
        $tests[] = array($node, '$this->renderBlock("foo", $context, $blocks)');
        // render: with args
        $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(array('named_arg' => Apishka_Templater_Node_Expression_Constant::apishka('bar', 1))), false, 1);
        $tests[] = array($node, '$this->renderBlock("foo", array_replace($context, array("named_arg" => "bar",)), $blocks)');
        // display: no args
        $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(), false, 1);
        $node->setAttribute('output', true);
        $tests[] = array($node, '// line 1' . PHP_EOL . '$this->displayBlock("foo", $context, $blocks);');
        // display: with args
        $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(array('named_arg' => Apishka_Templater_Node_Expression_Constant::apishka('bar', 1))), false, 1);
        $node->setAttribute('output', true);
        $tests[] = array($node, '// line 1
$this->displayBlock("foo", array_replace($context, array("named_arg" => "bar",)), $blocks);');
        return $tests;
    }
Пример #3
0
 public function getFunctionNode($name, $line)
 {
     switch ($name) {
         case 'parent':
             $this->parseArguments();
             if (!count($this->parser->getBlockStack())) {
                 throw new Apishka_Templater_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getFilename());
             }
             if (!$this->parser->getParent() && !$this->parser->hasTraits()) {
                 throw new Apishka_Templater_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getFilename());
             }
             return Apishka_Templater_Node_Expression_Parent::apishka($this->parser->peekBlockStack(), $line);
         case 'block':
             $args = $this->parseArguments(true, false, true);
             if (count($args) < 1) {
                 throw new Apishka_Templater_Error_Syntax('The "block" function takes at least one argument (the variable and the attributes).', $line, $this->parser->getFilename());
             }
             $block_name = $args->getNode('__first_arg__');
             $args->removeNode('__first_arg__');
             return Apishka_Templater_Node_Expression_BlockReference::apishka($block_name, $args, false, $line);
         case 'attribute':
             $args = $this->parseArguments();
             if (count($args) < 2) {
                 throw new Apishka_Templater_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getFilename());
             }
             return Apishka_Templater_Node_Expression_GetAttr::apishka($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Apishka_Templater_TemplateAbstract::ANY_CALL, $line);
         default:
             return $this->getFunctionNodeDefault($name, $line);
     }
 }
Пример #4
0
 public function getTestsForBlock()
 {
     $tests = array();
     $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(), false, 1);
     $node->setAttribute('output', true);
     $tests[] = array('{{ block("foo") }}', $node);
     $node = Apishka_Templater_Node_Expression_BlockReference::apishka(Apishka_Templater_Node_Expression_Constant::apishka('foo', 1), Apishka_Templater_Node::apishka(array('named_arg' => Apishka_Templater_Node_Expression_Constant::apishka('bar', 1))), false, 1);
     $node->setAttribute('output', true);
     $tests[] = array('{{ block("foo", named_arg="bar") }}', $node);
     return $tests;
 }