tests: add engine `nitg-sg` for --semi-global
[nit.git] / lib / html.nit
index d6c8092..4fc8530 100644 (file)
@@ -194,7 +194,25 @@ class HTMLTag
        #     var ul = new HTMLTag("ul")
        #     ul.add(new HTMLTag("li"))
        #     assert ul.write_to_string    == "<ul><li></li></ul>"
-       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    == "<ul><li>12</li><li>34</li></ul>"
+       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]