/**
  * @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 : '';
 }
Пример #2
0
 /**
  * @author Andreas Glaser
  */
 public function testImage()
 {
     $this->assertEquals('<img id="CHESTNUT" class="horseradish cheese peanuts" src="/my-url/test.png" data-beef-steak="XYZ " />', HtmlHelper::image('/my-url/test.png', $this->testAttributes));
 }
 /**
  * @param                                              $name
  * @param \AndreasGlaser\Helpers\Html\AttributesHelper|array|null $attributesHelper
  *
  * @return string
  * @author Andreas Glaser
  */
 public static function glyphIcon($name, $attributesHelper = null)
 {
     $attributesHelper = AttributesHelper::f($attributesHelper);
     return HtmlHelper::span('', $attributesHelper->addClass('glyphicon')->addClass('glyphicon-' . $name));
 }
Пример #4
0
 /**
  * @param            $value
  * @param            $text
  * @param bool|false $selected
  *
  * @return string
  * @author Andreas Glaser
  */
 public static function option($value, $text, $selected = false)
 {
     $attributesHelper = AttributesHelper::f();
     $attributesHelper->set('value', $value);
     if ($selected) {
         $attributesHelper->set('selected', 'selected');
     }
     return '<option' . $attributesHelper . '>' . HtmlHelper::chars($text) . '</option>';
 }