lib/html: make `attrs`, `classes` and `css_props` lazy.
authorJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 14:57:16 +0000 (10:57 -0400)
committerJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 15:04:13 +0000 (11:04 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/html/html.nit

index 72284ef..b4a62be 100644 (file)
@@ -128,7 +128,7 @@ class HTMLTag
        end
 
        # Tag attributes map
-       var attrs: Map[String, String] = new HashMap[String, String]
+       var attrs: Map[String, String] = new HashMap[String, String] is lazy
 
        # Get the attributed value of 'prop' or null if 'prop' is undifened
        #
@@ -161,7 +161,7 @@ class HTMLTag
        end
 
        # CSS classes
-       var classes: Set[String] = new HashSet[String]
+       var classes: Set[String] = new HashSet[String] is lazy
 
        # Add multiple CSS classes
        #
@@ -182,7 +182,7 @@ class HTMLTag
                css_props[prop] = value
                return self
        end
-       private var css_props: Map[String, String] = new HashMap[String, String]
+       private var css_props: Map[String, String] = new HashMap[String, String] is lazy
 
        # Get CSS value for 'prop'
        #
@@ -312,6 +312,7 @@ class HTMLTag
        end
 
        private fun render_attrs_in(res: Sequence[String]) do
+               if not isset _attrs and not isset _classes and not isset _css_props then return
                if attrs.has_key("class") or not classes.is_empty then
                        res.add " class=\""
                        for cls in classes do