X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/lib/html/html.nit b/lib/html/html.nit index 4fc8530..b0d6f65 100644 --- a/lib/html/html.nit +++ b/lib/html/html.nit @@ -27,7 +27,7 @@ module html # HTMLPage use fluent interface so you can chain calls as: # add("div").attr("id", "mydiv").text("My Div") class HTMLPage - super Streamable + super Writable # Define head content fun head do end @@ -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 + super Writable - # 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 == """Hello
World!