getTag() public method

public getTag ( )
示例#1
0
 /**
  * Html close tag
  *
  * @param Element  $element  Element
  *
  * @return string
  */
 public static function close(Element $element)
 {
     $tag = $element->getTag();
     return $tag == 'input' ? '' : "</{$tag}>";
 }
示例#2
0
 protected function writeElement(Element $element, $level)
 {
     $children = $element->getChildren();
     $childCount = count($children);
     $hasChildren = $childCount > 0;
     $newLine = $this->_pretty ? $this->_newLine : '';
     $indent = $this->_pretty ? str_repeat($this->_tabString, $level) : '';
     $str = $indent;
     $str .= $this->writeOpenTag($element->getTag(), $element->getAttributes(), $hasChildren);
     $writeCloseIndent = false;
     if ($hasChildren) {
         if ($childCount === 1 && $children[0] instanceof Text && mb_strlen($children[0]->getText(), 'utf-8') < $this->_textWrap) {
             $str .= $children[0]->getText();
         } else {
             $str .= $newLine;
             for ($i = 0; $i < $childCount; $i++) {
                 $child = $children[$i];
                 $str .= $this->writeLeaf($child, $level + 1);
                 $str .= $newLine;
             }
             $writeCloseIndent = true;
         }
     }
     if ($hasChildren || !empty($this->_selfClosingTags) && !in_array($element->getTag(), $this->_selfClosingTags)) {
         if ($hasChildren && $writeCloseIndent) {
             $str .= $indent;
         }
         $str .= $this->writeCloseTag($element->getTag());
     }
     return $str;
 }
示例#3
0
 private function renderHtml(Element $element)
 {
     $output = '';
     if ($this->getIndentationLevel() > 0) {
         $output .= $this->getSpaces() . '<' . $element->getTag();
     } else {
         $output .= '<' . $element->getTag();
     }
     if ($element->useAttsHelper()) {
         $output .= ' <?php atts(array(';
         if (($atts = $element->getAttributes()) != null) {
             if (isset($atts['id'])) {
                 $output .= "'id' => " . $this->_renderArrayValue($atts['id'], '_', 'php') . ', ';
                 unset($atts['id']);
             }
             if (isset($atts['class'])) {
                 $output .= "'class' => " . $this->_renderArrayValue($atts['class'], ' ', 'php') . ', ';
                 unset($atts['class']);
             }
             foreach ($atts as $name => $att) {
                 $output .= "";
                 switch ($att['t']) {
                     case 'str':
                         $interpolation = new Interpolation($att['v'], true);
                         $att_value = $interpolation->render();
                         $output .= "'{$name}' => {$att_value}, ";
                         continue;
                     case 'php':
                         if (is_array($att['v'])) {
                             $output .= "'{$name}' => array(" . join(',', $att['v']) . ')';
                         } else {
                             $output .= "'{$name}' => {$att['v']}, ";
                         }
                         continue;
                     case 'static':
                         $output .= "'{$name}' => '{$name}', ";
                         continue;
                     case 'function':
                         $output .= "{$att['v']}, ";
                         continue;
                 }
             }
         }
         $output = rtrim($output, ', ');
         $output .= ')); ?>';
     } else {
         if (($atts = $element->getAttributes()) !== null) {
             if (isset($atts['id'])) {
                 $output .= ' id="' . $this->_renderArrayValue($atts['id'], '_', 'txt') . '"';
                 unset($atts['id']);
             }
             if (isset($atts['class'])) {
                 $output .= ' class="' . $this->_renderArrayValue($atts['class'], ' ', 'txt') . '"';
                 unset($atts['class']);
             }
             foreach ($atts as $name => $att) {
                 switch ($att['t']) {
                     case 'str':
                         $output .= " {$name}={$att['v']}";
                         continue;
                     case 'php':
                         $output .= " {$name}=<?php {$att['v']}; ?>";
                         continue;
                     case 'static':
                         $output .= " {$name}=\"{$name}\"";
                         continue;
                 }
             }
         }
     }
     $interpolation = new Interpolation($output);
     $output = $interpolation->render();
     if ($this->_el->isSelfClosing()) {
         $output .= ' />';
     } else {
         // render inline content
         $content = $this->renderTagContent($element->getInlineContent());
         $output .= '>' . $content . '</' . $element->getTag() . '>';
     }
     return $output . "\n";
 }