lib/html: implement the tag list as an hashset instead of a array.
[nit.git] / lib / html / html.nit
index 9b88578..72284ef 100644 (file)
@@ -107,7 +107,12 @@ class HTMLTag
        # `"div"` for `<div></div>`.
        var tag: String
        init do
-               self.is_void = (once ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]).has(tag)
+               self.is_void = (once void_list).has(tag)
+       end
+
+       private fun void_list: Set[String]
+       do
+               return new HashSet[String].from(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"])
        end
 
        # Is the HTML element a void element?
@@ -126,6 +131,7 @@ class HTMLTag
        var attrs: Map[String, String] = new HashMap[String, String]
 
        # Get the attributed value of 'prop' or null if 'prop' is undifened
+       #
        #     var img = new HTMLTag("img")
        #     img.attr("src", "./image.png").attr("alt", "image")
        #     assert img.get_attr("src")     == "./image.png"
@@ -135,6 +141,7 @@ class HTMLTag
        end
 
        # Set a 'value' for 'key'
+       #
        #     var img = new HTMLTag("img")
        #     img.attr("src", "./image.png").attr("alt", "image")
        #     assert img.write_to_string      == """<img src=".&#47;image.png" alt="image"/>"""
@@ -144,6 +151,7 @@ class HTMLTag
        end
 
        # Add a CSS class to the HTML tag
+       #
        #     var img = new HTMLTag("img")
        #     img.add_class("logo").add_class("fullpage")
        #     assert img.write_to_string      == """<img class="logo fullpage"/>"""
@@ -156,6 +164,7 @@ class HTMLTag
        var classes: Set[String] = new HashSet[String]
 
        # Add multiple CSS classes
+       #
        #     var img = new HTMLTag("img")
        #     img.add_classes(["logo", "fullpage"])
        #     assert img.write_to_string      == """<img class="logo fullpage"/>"""
@@ -165,6 +174,7 @@ class HTMLTag
        end
 
        # Set a CSS 'value' for 'prop'
+       #
        #     var img = new HTMLTag("img")
        #     img.css("border", "2px solid black").css("position", "absolute")
        #     assert img.write_to_string      == """<img style="border: 2px solid black; position: absolute"/>"""
@@ -175,6 +185,7 @@ class HTMLTag
        private var css_props: Map[String, String] = new HashMap[String, String]
 
        # Get CSS value for 'prop'
+       #
        #     var img = new HTMLTag("img")
        #     img.css("border", "2px solid black").css("position", "absolute")
        #     assert img.get_css("border")    == "2px solid black"
@@ -208,6 +219,7 @@ class HTMLTag
         end
 
        # Add a HTML 'child' to self
+       #
        #     var ul = new HTMLTag("ul")
        #     ul.add(new HTMLTag("li"))
        #     assert ul.write_to_string    == "<ul><li></li></ul>"
@@ -235,10 +247,11 @@ class HTMLTag
        var children: Set[HTMLTag] = new HashSet[HTMLTag]
 
        # Clear all child and set the text of element
+       #
        #     var p = new HTMLTag("p")
        #     p.text("Hello World!")
        #     assert p.write_to_string      ==  "<p>Hello World!</p>"
-       # Text is escaped see: `standard::String::html_escape`
+       # Text is escaped see: `core::String::html_escape`
        fun text(txt: String): HTMLTag do
 
                children.clear
@@ -247,12 +260,13 @@ class HTMLTag
        end
 
        # Append text to element
+       #
        #     var p = new HTMLTag("p")
        #     p.append("Hello")
        #     p.add(new HTMLTag("br"))
        #     p.append("World!")
        #     assert p.write_to_string      ==  "<p>Hello<br/>World!</p>"
-       # Text is escaped see: standard::String::html_escape
+       # Text is escaped see: core::String::html_escape
        fun append(txt: String): HTMLTag do
                add(new HTMLRaw("", txt.html_escape))
                return self