lib/html: bootstrap use optional annotation
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 25 Oct 2017 02:01:36 +0000 (22:01 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 23 Nov 2017 16:08:41 +0000 (11:08 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/html/bootstrap.nit
src/doc/html_templates/html_components.nit
src/doc/html_templates/html_model.nit
src/doc/html_templates/html_templates.nit
src/doc/html_templates/model_html.nit

index 7b5084f..cc3d6e2 100644 (file)
@@ -31,7 +31,7 @@ abstract class BSComponent
        super Template
 
        # CSS classes to add on this element.
-       var css_classes = new Array[String]
+       var css_classes = new Array[String] is optional
 
        # Render `self` css clases as a `class` attribute.
        fun render_css_classes: String do
@@ -53,11 +53,12 @@ end
 #
 # Creates a link with a title attribute:
 # ~~~
-# lnk = new Link.with_title("http://nitlanguage.org", "Nit", "Nit homepage")
+# lnk = new Link("http://nitlanguage.org", "Nit", "Nit homepage")
 # assert lnk.write_to_string == "<a href=\"http://nitlanguage.org\" title=\"Nit homepage\">Nit</a>"
 # ~~~
 class Link
        super BSComponent
+       autoinit(href, text, title, css_classes)
 
        # URL pointed by this link.
        var href: String is writable
@@ -66,13 +67,7 @@ class Link
        var text: Writable is writable
 
        # Optional title.
-       var title: nullable String is noinit, writable
-
-       # Creates a link with a `title` attribute.
-       init with_title(href: String, text: Writable, title: nullable String) do
-               init(href, text)
-               self.title = title
-       end
+       var title: nullable String = null is optional, writable
 
        redef fun rendering do
                add "<a{render_css_classes} href=\"{href}\""
@@ -95,11 +90,12 @@ end
 #
 # With subtext:
 # ~~~
-# var h6 = new Header.with_subtext(6, "Title", "with subtext")
+# var h6 = new Header(6, "Title", "with subtext")
 # assert h6.write_to_string == "<h6>Title<small>with subtext</small></h6>"
 # ~~~
 class Header
        super BSComponent
+       autoinit(level, text, subtext, id, css_classes)
 
        # Header level between 1 and 6.
        var level: Int
@@ -108,13 +104,10 @@ class Header
        var text: Writable
 
        # Optional subtext.
-       var subtext: nullable Writable is noinit, writable
+       var subtext: nullable Writable = null is optional, writable
 
-       # Creates a link with a `title` attribute.
-       init with_subtext(level: Int, text: Writable, subtext: String) do
-               init(level, text)
-               self.subtext = subtext
-       end
+       # Optional id.
+       var id: nullable String = null is optional, writable
 
        redef fun rendering do
                add "<h{level}{render_css_classes}>{text.write_to_string}"
@@ -131,11 +124,12 @@ end
 # Used to factorize behavior between OrderedList and UnorderedList.
 abstract class HTMLList
        super BSComponent
+       autoinit(items, css_classes)
 
        # A list contains `<li>` tags as children.
        #
        # See ListItem.
-       var items = new Array[ListItem]
+       var items = new Array[ListItem] is optional
 
        # Adds a new ListItem to `self`.
        fun add_li(item: ListItem) do items.add item
@@ -203,6 +197,7 @@ end
 # A `<li>` tag.
 class ListItem
        super BSComponent
+       autoinit(text, css_classes)
 
        # Content to display in this list item.
        var text: Writable is writable
@@ -222,6 +217,7 @@ end
 # ~~~
 class BSIcon
        super BSComponent
+       autoinit(icon, css_classes)
 
        # Glyphicon name to display.
        #
@@ -278,6 +274,7 @@ end
 # ~~~
 class BSLabel
        super BSComponent
+       autoinit(color, text, css_classes)
 
        # Class used to change the color of the label.
        #
@@ -306,6 +303,7 @@ end
 # ~~~
 class BSBadge
        super BSComponent
+       autoinit(text, css_classes)
 
        # Text to display in the label.
        var text: Writable
@@ -333,6 +331,7 @@ end
 # ~~~
 class BSPageHeader
        super BSComponent
+       autoinit(text, css_classes)
 
        # Text to display as title.
        var text: Writable
@@ -362,6 +361,7 @@ end
 # ~~~
 class BSAlert
        super BSComponent
+       autoinit(color, text, is_dismissible, css_classes)
 
        # Class used to change the color of the alert.
        #
@@ -376,7 +376,7 @@ class BSAlert
        # See http://getbootstrap.com/components/#alerts-dismissible
        #
        # Default is `false`.
-       var is_dismissible = false
+       var is_dismissible = false is optional, writable
 
        init do css_classes.add "alert alert-{color}"
 
@@ -399,7 +399,7 @@ end
 # Example:
 #
 # ~~~
-# var p = new BSPanel("default", "Panel content")
+# var p = new BSPanel("default", body = "Panel content")
 #
 # assert p.write_to_string == """
 # <div class="panel panel-default">
@@ -413,8 +413,7 @@ end
 # Panel with heading:
 #
 # ~~~
-# p = new BSPanel("danger", "Panel content")
-# p.heading = "Panel heading"
+# p = new BSPanel("danger", heading = "Panel heading", body = "Panel content")
 #
 # assert p.write_to_string == """
 # <div class="panel panel-danger">
@@ -429,20 +428,21 @@ end
 # ~~~
 class BSPanel
        super BSComponent
+       autoinit(color, heading, body, footer, css_classes)
 
        # Panel color.
        #
        # Can be one of `default`, `primary`, `success`, `info`, `warning` or `danger`.
-       var color: String
+       var color: String is writable
 
        # Panel header if any.
-       var heading: nullable Writable is noinit, writable
+       var heading: nullable Writable = null is optional, writable
 
        # Body to display in the panel.
-       var body: Writable
+       var body: nullable Writable = null is optional, writable
 
        # Panel footer is any.
-       var footer: nullable Writable is noinit, writable
+       var footer: nullable Writable = null is optional, writable
 
        init do css_classes.add "panel panel-{color}"
 
@@ -454,9 +454,12 @@ class BSPanel
                        addn heading.write_to_string
                        addn "</div>"
                end
-               addn "<div class=\"panel-body\">"
-               addn body.write_to_string
-               addn "</div>"
+               var body = self.body
+               if body != null then
+                       addn "<div class=\"panel-body\">"
+                       addn body.write_to_string
+                       addn "</div>"
+               end
                var footer = self.footer
                if footer != null then
                        addn "<div class=\"panel-footer\">"
index a0f1399..fa3bd69 100644 (file)
@@ -39,6 +39,7 @@ end
 # A component that display tabbed data.
 class DocTabs
        super BSComponent
+       autoinit(html_id, drop_text, css_classes)
 
        # HTML id of this component.
        var html_id: String
@@ -80,6 +81,7 @@ end
 # A list of tab regrouped in a dropdown
 class DocTabsDrop
        super UnorderedList
+       autoinit(html_id, html_title, items, css_classes)
 
        # HTML id used by the tabs group.
        var html_id: String
@@ -108,6 +110,7 @@ end
 # A panel that goes in a DocTabs.
 class DocTabPanel
        super BSComponent
+       autoinit(html_id, tab_title, html_content, is_active, css_classes)
 
        # HTML id of this panel.
        var html_id: String
@@ -119,7 +122,7 @@ class DocTabPanel
        var html_content: Writable is writable
 
        # Is this panel visible by default?
-       var is_active = false
+       var is_active = false is optional
 
        redef fun rendering do
                var active = ""
@@ -136,6 +139,7 @@ end
 # A ListItem that goes in a DocTabsDrop.
 private class DocTabItem
        super ListItem
+       autoinit(text, target_id, css_classes)
 
        # Panel id to trigger when the link is clicked.
        var target_id: String
index b8107ee..820a9a3 100644 (file)
@@ -143,7 +143,7 @@ end
 
 redef class MParameterType
        redef fun html_link do
-               return new Link.with_title("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name, "formal type")
+               return new Link("{mclass.nitdoc_url}#FT_{name.to_cmangle}", name, "formal type")
        end
 end
 
@@ -191,7 +191,7 @@ redef class MConcern
        private fun html_concern_item: ListItem do
                var lnk = html_link
                var tpl = new Template
-               tpl.add new Link.with_title("#{nitdoc_id}.concern", lnk.text, lnk.title)
+               tpl.add new Link("#{nitdoc_id}.concern", lnk.text, lnk.title)
                var comment = html_synopsis
                if comment != null then
                        tpl.add ": "
index a7a5b9a..9f8390e 100644 (file)
@@ -334,6 +334,8 @@ end
 redef class DocSection
        super BSComponent
 
+       redef fun css_classes do return new Array[String]
+
        redef fun rendering do
                if is_hidden then
                        addn "<a id=\"{html_id}\"></a>"
@@ -349,6 +351,8 @@ end
 redef class DocArticle
        super BSComponent
 
+       redef fun css_classes do return new Array[String]
+
        redef fun rendering do
                if is_hidden then return
                addn "<article{render_css_classes} id=\"{html_id}\">"
index 20ae4ed..8e89dd4 100644 (file)
@@ -539,7 +539,7 @@ redef class MGenericType
        redef fun html_short_signature do
                var lnk = html_link
                var tpl = new Template
-               tpl.add new Link.with_title(lnk.href, mclass.name.html_escape, lnk.title)
+               tpl.add new Link(lnk.href, mclass.name.html_escape, lnk.title)
                tpl.add "["
                for i in [0..arguments.length[ do
                        tpl.add arguments[i].html_short_signature
@@ -552,7 +552,7 @@ redef class MGenericType
        redef fun html_signature do
                var lnk = html_link
                var tpl = new Template
-               tpl.add new Link.with_title(lnk.href, mclass.name.html_escape, lnk.title)
+               tpl.add new Link(lnk.href, mclass.name.html_escape, lnk.title)
                tpl.add "["
                for i in [0..arguments.length[ do
                        tpl.add arguments[i].html_signature