/**
  * @param \AndreasGlaser\Helpers\Interfaces\RendererInterface|null $renderer
  *
  * @return string
  * @author Andreas Glaser
  */
 public function render(RendererInterface $renderer = null)
 {
     if ($renderer) {
         return $renderer->render($this);
     }
     $html = '<dl' . $this->attributes . '>';
     $itemCount = count($this->items);
     $itemIndex = 0;
     foreach ($this->items as $item) {
         /** @var AttributesHelper $termAttributes */
         $termAttributes = $item['termAttributes'];
         /** @var AttributesHelper $contentAttributes */
         $contentAttributes = $item['contentAttributes'];
         if ($itemIndex === 0) {
             $termAttributes->addClass('item-first');
             $contentAttributes->addClass('item-first');
         }
         if ($itemIndex === $itemCount - 1) {
             $termAttributes->addClass('item-last');
             $contentAttributes->addClass('item-last');
         }
         $termAttributes->addClass('item-index-' . $itemIndex);
         $contentAttributes->addClass('item-index-' . $itemIndex);
         $html .= '<dt' . $termAttributes . '>' . $item['term'] . '</dt>';
         $html .= '<dd' . $contentAttributes . '>' . $item['content'] . '</dd>';
         $itemIndex++;
     }
     $html .= '</dl>';
     return $html;
 }
 /**
  * @param \AndreasGlaser\Helpers\Interfaces\RendererInterface|null $renderer
  *
  * @return string
  * @author Andreas Glaser
  */
 public function render(RendererInterface $renderer = null)
 {
     if ($renderer) {
         return $renderer->render($this);
     }
     $attributes = null;
     if ($this->hasId()) {
         $attributes = 'id="' . $this->getId() . '"';
     }
     if ($this->hasClasses()) {
         $attributes .= ' class="' . HtmlHelper::chars($this->getClassesImploded()) . '"';
     }
     foreach ($this->attributes as $name => $value) {
         $attributes .= ' ' . $name . '="' . HtmlHelper::chars($value) . '"';
     }
     $data = $this->getData();
     if (!empty($data)) {
         foreach ($data as $key => $value) {
             $attributes .= ' data-' . $key . '="' . $value . '"';
         }
     }
     $styles = $this->getStyles();
     if (!empty($styles)) {
         $stylesCompiled = null;
         foreach ($styles as $name => $value) {
             $stylesCompiled .= $name . ':' . $value . ';';
         }
         $attributes .= ' style="' . $stylesCompiled . '"';
     }
     $attributes = trim($attributes);
     return !empty($attributes) ? ' ' . $attributes : '';
 }
Example #3
0
 /**
  * @param \AndreasGlaser\Helpers\Interfaces\RendererInterface|null $renderer
  *
  * @return string
  * @author Andreas Glaser
  */
 public function render(RendererInterface $renderer = null)
 {
     if ($renderer) {
         return $renderer->render($this);
     }
     return '<td' . $this->attributes->render() . '>' . $this->content . '</td>';
 }
 /**
  * @param \AndreasGlaser\Helpers\Interfaces\RendererInterface|null $renderer
  *
  * @return string
  * @author Andreas Glaser
  */
 public function render(RendererInterface $renderer = null)
 {
     if ($renderer) {
         return $renderer->render($this);
     }
     $html = '<table' . $this->getAttributes()->render() . '>';
     $headRows = $this->getHeadRows();
     if (!empty($headRows)) {
         $html .= '<thead>';
         foreach ($headRows as $row) {
             $html .= $row->render();
         }
         $html .= '</thead>';
     }
     $bodyRows = $this->getBodyRows();
     if (!empty($bodyRows)) {
         $html .= '<tbody>';
         foreach ($bodyRows as $row) {
             $html .= $row->render();
         }
         $html .= '</tbody>';
     }
     $html .= '</table>';
     return $html;
 }
Example #5
0
 /**
  * @param \AndreasGlaser\Helpers\Interfaces\RendererInterface|null $renderer
  *
  * @return string
  * @author Andreas Glaser
  */
 public function render(RendererInterface $renderer = null)
 {
     if ($renderer) {
         return $renderer->render($this);
     }
     $html = '<tr' . $this->attributes->render() . '>';
     foreach ($this->getCells() as $cell) {
         $html .= $cell->render();
     }
     $html .= '</tr>';
     return $html;
 }