Example #1
0
 public function testAddAttribute()
 {
     $tag = new Tag();
     $tag->disableAutoDump();
     $tag->addAttribute('test', 'value');
     $this->assertEquals('value', $tag->getAttribute('test'));
     $this->assertEquals(['test' => 'value', 'class' => []], $tag->getAttributes()->toArray());
     $tag->addAttributes(['test2' => 'value2', 'test' => 'value3']);
     $this->assertEquals('value3', $tag->getAttribute('test'));
     $this->assertEquals(['test' => 'value3', 'class' => [], 'test2' => 'value2'], $tag->getAttributes()->toArray());
 }
 public function render(Tag $tag)
 {
     if ($tag->isClosingTag()) {
         $tag->close(false);
         return '</' . $tag->getTag() . '>';
     } else {
         $html = '<' . trim(implode(' ', [$tag->getTag(), $tag->getAttributes()])) . '>';
         if (!$tag->getContent()->isEmpty()) {
             $chunks = new Collection();
             $tag->getContent()->each(function ($chunk) use(&$chunks) {
                 $content = (string) $chunk;
                 if ($content) {
                     $chunks[] = $content;
                 }
             });
             $html .= $chunks->join($tag->getSeparator())->trim();
             $html .= '</' . $tag->getTag() . '>';
         } elseif ($tag->isAlwaysClosed()) {
             $html .= '</' . $tag->getTag() . '>';
         }
         return $html;
     }
 }