Example #1
0
 /**
  * Parse the next token
  *
  * @return void
  */
 protected function next()
 {
     $token = $this->currentToken();
     // current token has to be an identifier
     if ($token->type !== 'identifier') {
         throw $this->errorUnexpectedToken($token);
     }
     $this->tag->setName($token->getValue());
     $this->skipToken();
     // we use all tokens until a linebreak in the short tag
     $tokens = $this->getTokensUntilLinebreak();
     $attributeTokens = array();
     // retrieve all attribute tokens
     foreach ($tokens as $key => $token) {
         if ($token->type === 'assignText') {
             break;
         }
         $attributeTokens[] = $token;
         unset($tokens[$key]);
     }
     // now lets parse the attributes
     $this->tag->attributes = $this->parseAttributeTokens($attributeTokens);
     // reset the token array keys
     $tokens = array_values($tokens);
     if (!empty($tokens) && $tokens[0]->type === 'assignText') {
         unset($tokens[0]);
         $this->tag->addChild(new TextNode($this->parseChild('Expression', $tokens, false)));
     }
     // return the result
     return $this->node();
 }
Example #2
0
 /**
  * tests Parser
  */
 public function testTagWithAttributes()
 {
     $tag = new Tag();
     $tag->setName('input');
     $tag->attributes = array('name' => 'username', 'type' => 'text');
     $tag = $this->compile($tag);
     $this->assertContains("array('name' => 'username', 'type' => 'text')", $tag);
 }
Example #3
0
 /**
  * tests Parser
  */
 public function testBasic()
 {
     $node = new Scope();
     $tag = new Tag();
     $tag->setName('button');
     $node->addChild($tag);
     $node = $this->compile($node);
     $this->assertContains("if (!isset(\$__tattoo_vars)) {", $node);
     $this->assertContains("\$__tattoo_vars = array();", $node);
 }
Example #4
0
 /**
  * Parse the next token
  *
  * @return void
  */
 protected function next()
 {
     // check that a tag is being opend
     if ($this->currentToken()->type !== 'tagOpen') {
         throw $this->errorUnexpectedToken($this->currentToken());
     }
     // the normal tag is baiscally a short tag with out the
     // tag tokens so we simply strip them
     $this->skipToken();
     // get all tokens until tag close
     $tokens = $this->getTokensUntil('tagClose');
     $this->skipToken();
     // we might have tag recursion
     if ($this->currentToken() && $this->currentToken()->type === 'tagOpen') {
         $this->tag = $this->parseChild('ShortTag', $tokens, false);
         $this->tag->addChild($this->parseChild('Tag'));
         return $this->node();
     }
     // and add the tokens until linebreak
     $tokens = array_merge($tokens, $this->getTokensUntil(array('linebreak', 'scopeOpen')));
     // parse the short tag as base
     $this->tag = $this->parseChild('ShortTag', $tokens, false);
     // we might have some linebreak
     $this->skipTokensOfType('linebreak');
     // is there a following scope
     if ($this->currentToken() && $this->currentToken()->type === 'scopeOpen') {
         // now parse the rest of the scope
         if ($scopeTokens = $this->getTokensUntilClosingScope()) {
             $scopeParse = new Scope($scopeTokens);
             // assign the parsed children to the current tag
             foreach ($scopeParse->parse()->getChildren() as $child) {
                 $this->tag->addChild($child);
             }
         }
     }
     return $this->node();
 }