コード例 #1
0
ファイル: TagTest.php プロジェクト: primalbase/html-tag2
 public function testPrepend()
 {
     $this->assertEquals('<div><span>content</span></div>', (string) Tag::div()->prepend(Tag::span('content')));
     $this->assertEquals('<div><span>content1</span><span>content2</span></div>', (string) Tag::div(Tag::span('content2'))->prepend(Tag::span('content1')));
     $this->assertEquals('<ul><li>item1</li><li>item2</li>outer</ul>', (string) Tag::ul()->prepend(TagNodes::create(Tag::li('item1'), Tag::li('item2'), 'outer')));
     $this->assertEquals((string) TagNodes::create()->prepend('<strong></strong>'), '&lt;strong&gt;&lt;/strong&gt;');
     $this->assertEquals((string) Tag::div()->prepend('<strong></strong>'), '<div>&lt;strong&gt;&lt;/strong&gt;</div>');
 }
コード例 #2
0
ファイル: TagNodesTest.php プロジェクト: primalbase/html-tag2
 public function testConstruct()
 {
     $this->assertEquals((string) TagNodes::create(), '');
     $this->assertEquals((string) TagNodes::create('hoge fuga'), 'hoge fuga');
     $this->assertEquals((string) TagNodes::create(Tag::b()), '<b></b>');
     $this->assertEquals((string) TagNodes::create()->append(Tag::hr()), '<hr>');
     $this->assertEquals('<li>item1</li><li>item2</li>', (string) TagNodes::create(Tag::li('item1'), Tag::li('item2')));
     $this->assertEquals((string) TagNodes::create(1), '1', 'Add a integer.');
     $this->assertEquals((string) TagNodes::create(1.0), '1.0', 'Add a float.');
     $this->assertEquals((string) TagNodes::create(array('a', 'b', 'c')), 'abc', 'Add an array.');
 }
コード例 #3
0
ファイル: Tag.php プロジェクト: primalbase/html-tag2
 public function __toString()
 {
     $is_block_tag = !$this->doc->isInlineTag($this->tagName);
     $is_empty_tag = $this->doc->isEmptyTag($this->tagName);
     $open_tag = $this->doc->openTag($this->tagName, $this->attributes);
     $close_tag = $this->doc->closeTag($this->tagName);
     $parts = array();
     array_push($parts, $open_tag);
     if ($is_empty_tag) {
         if (self::$codeFormat && self::$codeFormatIndent == 0) {
             array_push($parts, PHP_EOL);
         }
         return implode('', $parts);
     }
     if (in_array($this->tagName, array('script', 'style'))) {
         if (self::$codeFormat) {
             array_push($parts, PHP_EOL);
         }
         array_push($parts, $this->nodes->rawString());
         if (self::$codeFormat) {
             array_push($parts, PHP_EOL);
         }
         if (self::$codeFormat) {
             array_push($parts, self::indent());
         }
         array_push($parts, $close_tag);
         if (self::$codeFormatIndent == 0) {
             array_push($parts, PHP_EOL);
         }
         return implode('', $parts);
     }
     if (!$this->nodes->isEmpty()) {
         foreach ($this->nodes as $node) {
             self::$codeFormatIndent++;
             if (self::$codeFormat && $is_block_tag) {
                 array_push($parts, PHP_EOL);
             }
             if (self::$codeFormat && $is_block_tag) {
                 array_push($parts, self::indent());
             }
             array_push($parts, TagNodes::escapedString($node));
             self::$codeFormatIndent--;
         }
     }
     if (self::$codeFormat && $is_block_tag) {
         array_push($parts, PHP_EOL);
         array_push($parts, self::indent());
     }
     array_push($parts, $close_tag);
     if (self::$codeFormat && self::$codeFormatIndent == 0) {
         array_push($parts, PHP_EOL);
     }
     return implode('', $parts);
 }