X-Git-Url: http://nitlanguage.org
diff --git a/lib/html.nit b/lib/html.nit
index f49ba3a..4fc8530 100644
--- a/lib/html.nit
+++ b/lib/html.nit
@@ -96,8 +96,8 @@ class HTMLTag
# Is the HTML element a void element?
#
- # assert new HTMLTag("img").is_void == true
- # assert new HTMLTag("p").is_void == false
+ # assert (new HTMLTag("img")).is_void == true
+ # assert (new HTMLTag("p")).is_void == false
var is_void: Bool
init with_attrs(tag: String, attrs: Map[String, String]) do
@@ -194,7 +194,25 @@ class HTMLTag
# var ul = new HTMLTag("ul")
# ul.add(new HTMLTag("li"))
# assert ul.write_to_string == "
"
- fun add(child: HTMLTag) do children.add(child)
+ # returns `self` for fluent programming
+ fun add(child: HTMLTag): HTMLTag
+ do
+ children.add(child)
+ return self
+ end
+
+ # Create a new HTMLTag child and return it
+ #
+ # var ul = new HTMLTag("ul")
+ # ul.open("li").append("1").append("2")
+ # ul.open("li").append("3").append("4")
+ # assert ul.write_to_string == ""
+ fun open(tag: String): HTMLTag
+ do
+ var res = new HTMLTag(tag)
+ add(res)
+ return res
+ end
# List of children HTML elements
var children: Set[HTMLTag] = new HashSet[HTMLTag]
@@ -224,11 +242,13 @@ class HTMLTag
end
# Append raw HTML to element
+ #
# var p = new HTMLTag("p")
# p.append("Hello")
- # p.add_raw_html("")
- # p.html #- "Hello
"
- # Note: the HTML in insered as it, no verification is done
+ # p.add_raw_html("foo")
+ # assert p.write_to_string == "Hellofoo
"
+ #
+ # Note: the HTML in insered as it, no verification is done.
fun add_raw_html(txt: String): HTMLTag do
add(new HTMLRaw(txt))
return self