/** * Render element as html string. * * @return string containing rendered html of this element and all its descendants */ public function branchToHtml() { try { if (!$this->willRenderInHtml()) { return ''; } $html_contents = $this->evaluate($this->html_contents); if (empty($html_contents) or $html_contents instanceof Collection and $html_contents->isEmpty()) { $html_contents = $this->evaluate($this->default_html_contents); } //Set this as parent on any content FluentHtmlElement that doesn't already have a parent $html_contents = HtmlBuilder::flatten($html_contents)->map(function ($item) { if ($item instanceof FluentHtmlElement and !$item->hasParent()) { $item->setParent($this); } return $item; }); $html_element_name = $this->getHtmlElementName(); if ($html_element_name) { $html_attributes = $this->evaluate($this->html_attributes); return HtmlBuilder::buildHtmlElement($html_element_name, $html_attributes, $html_contents); } else { return HtmlBuilder::buildContentsString($html_contents); } } catch (\Exception $e) { return '<!-- ' . get_class($e) . ' in ' . __METHOD__ . ': ' . $e->getMessage() . ' -->'; } }
public function testEmptyClassAttribute() { $this->assertEquals('<br>', HtmlBuilder::buildHtmlElement('br', ['class' => ['a' => false]])); }