# Create a HTML elements with the specifed type and attributes.
init with_attrs(tag: String, attrs: Map[String, String]) do
- self.tag = tag
+ init(tag)
self.attrs = attrs
end
end
# List of children HTML elements
- var children: Set[HTMLTag] = new HashSet[HTMLTag]
+ var children: Set[HTMLTag] = new HashSet[HTMLTag] is lazy
# Clear all child and set the text of element
#
# Text is escaped see: `core::String::html_escape`
fun text(txt: String): HTMLTag do
- children.clear
+ if isset _children then children.clear
append(txt)
return self
end
res.add "<"
res.add tag
render_attrs_in(res)
- if is_void and children.is_empty then
+ if is_void and (not isset _children or children.is_empty) then
res.add "/>"
else
res.add ">"
- for child in children do child.render_in(res)
+ if isset _children then for child in children do child.render_in(res)
res.add "</"
res.add tag
res.add ">"