From 2f2c4e5b80230dc0518a1b306e7d35062a682178 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 24 Oct 2017 22:01:36 -0400 Subject: [PATCH] lib/html: bootstrap use optional annotation Signed-off-by: Alexandre Terrasa --- lib/html/bootstrap.nit | 59 +++++++++++++++------------- src/doc/html_templates/html_components.nit | 6 ++- src/doc/html_templates/html_model.nit | 4 +- src/doc/html_templates/html_templates.nit | 4 ++ src/doc/html_templates/model_html.nit | 4 +- 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/lib/html/bootstrap.nit b/lib/html/bootstrap.nit index 7b5084f..cc3d6e2 100644 --- a/lib/html/bootstrap.nit +++ b/lib/html/bootstrap.nit @@ -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 == "Nit" # ~~~ 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 "Titlewith subtext" # ~~~ 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 "{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 `
  • ` 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 `
  • ` 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 == """ #
    @@ -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 == """ #
    @@ -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 "
    " end - addn "
    " - addn body.write_to_string - addn "
    " + var body = self.body + if body != null then + addn "
    " + addn body.write_to_string + addn "
    " + end var footer = self.footer if footer != null then addn "
    " diff --git a/src/doc/html_templates/html_components.nit b/src/doc/html_templates/html_components.nit index a0f1399..fa3bd69 100644 --- a/src/doc/html_templates/html_components.nit +++ b/src/doc/html_templates/html_components.nit @@ -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 diff --git a/src/doc/html_templates/html_model.nit b/src/doc/html_templates/html_model.nit index b8107ee..820a9a3 100644 --- a/src/doc/html_templates/html_model.nit +++ b/src/doc/html_templates/html_model.nit @@ -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 ": " diff --git a/src/doc/html_templates/html_templates.nit b/src/doc/html_templates/html_templates.nit index a7a5b9a..9f8390e 100644 --- a/src/doc/html_templates/html_templates.nit +++ b/src/doc/html_templates/html_templates.nit @@ -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 "" @@ -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 "" diff --git a/src/doc/html_templates/model_html.nit b/src/doc/html_templates/model_html.nit index 20ae4ed..8e89dd4 100644 --- a/src/doc/html_templates/model_html.nit +++ b/src/doc/html_templates/model_html.nit @@ -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 -- 1.7.9.5