X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/lib/html/html.nit b/lib/html/html.nit index 4fc8530..8d2de2b 100644 --- a/lib/html/html.nit +++ b/lib/html/html.nit @@ -60,7 +60,7 @@ class HTMLPage # Add a raw html string # add_html("top") - fun add_html(html: String) do current.add(new HTMLRaw(html)) + fun add_html(html: String) do current.add(new HTMLRaw("", html)) # Open a html tag # open("ul") @@ -84,13 +84,15 @@ class HTMLPage end end +# An HTML element. class HTMLTag super Streamable - # HTML tagname: 'div' for
+ # HTML element type. + # + # `"div"` for `
`. var tag: String - init(tag: String) do - self.tag = tag + init do self.is_void = (once ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]).has(tag) end @@ -98,8 +100,9 @@ class HTMLTag # # assert (new HTMLTag("img")).is_void == true # assert (new HTMLTag("p")).is_void == false - var is_void: Bool + var is_void: Bool is noinit + # Create a HTML elements with the specifed type and attributes. init with_attrs(tag: String, attrs: Map[String, String]) do self.tag = tag self.attrs = attrs @@ -120,7 +123,7 @@ class HTMLTag # Set a 'value' for 'key' # var img = new HTMLTag("img") # img.attr("src", "./image.png").attr("alt", "image") - # assert img.write_to_string == """image""" + # assert img.write_to_string == """image""" fun attr(key: String, value: String): HTMLTag do attrs[key] = value return self @@ -237,7 +240,7 @@ class HTMLTag # assert p.write_to_string == "

Hello
World!

" # Text is escaped see: standard::String::html_escape fun append(txt: String): HTMLTag do - add(new HTMLRaw(txt.html_escape)) + add(new HTMLRaw("", txt.html_escape)) return self end @@ -250,7 +253,7 @@ class HTMLTag # # Note: the HTML in insered as it, no verification is done. fun add_raw_html(txt: String): HTMLTag do - add(new HTMLRaw(txt)) + add(new HTMLRaw("", txt)) return self end @@ -326,7 +329,6 @@ end private class HTMLRaw super HTMLTag - private var content: String - init(content: String) do self.content = content + var content: String redef fun render_in(res) do res.add content end