src: transform all old writable in annotations
[nit.git] / src / doc / doc_templates.nit
index 726e229..1d1fb45 100644 (file)
@@ -23,25 +23,28 @@ class TplPage
        super Template
 
        # Page title in HTML header
-       var title: String writable
+       var title: String is writable, noinit
+
+       # Page url
+       var url: String is writable, noinit
 
        # Directory where css, js and other assets can be found
-       var shareurl: String writable
+       var shareurl: String is writable, noinit
 
        # Attributes of the body tag element
        var body_attrs = new Array[TagAttribute]
 
        # Top menu template if any
-       var topmenu: TplTopMenu writable
+       var topmenu: TplTopMenu is writable, noinit
 
        # Sidebar template if any
-       var sidebar: nullable TplSidebar writable
+       var sidebar: nullable TplSidebar = null is writable
 
        # Content of the page in form a TplSection
        var sections = new Array[TplSection]
 
        # Footer content if any
-       var footer: nullable Streamable writable
+       var footer: nullable Streamable = null is writable
 
        # JS scripts to append at the end of the body
        var scripts = new Array[TplScript]
@@ -105,7 +108,7 @@ class TplPage
                add "<script src='{shareurl}/vendors/jquery/jquery-1.11.1.min.js'></script>"
                add "<script src='{shareurl}/vendors/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
                add "<script src='{shareurl}/vendors/bootstrap/js/bootstrap.min.js'></script>"
-               add "<script data-main='{shareurl}/js/nitdoc' src='{shareurl}/js/lib/require.js'</script>"
+               add "<script data-main='{shareurl}/js/nitdoc' src='{shareurl}/js/lib/require.js'></script>"
                for script in scripts do add script
                add """<script>
                        $(function () {
@@ -150,11 +153,24 @@ class TplTopMenu
        super Template
 
        # Brand link to display in first position of the top menu
-       private var brand: nullable Streamable writable
+       private var brand: nullable Streamable = null is writable
        # Elements of the topmenu
        private var elts = new Array[Streamable]
 
-       init do end
+       # The page url where the top menu is displayed.
+       #
+       # Used to select the active link.
+       private var current_url: String
+
+       init(current_url: String) do
+               self.current_url = current_url
+       end
+
+       # Add a new link to the menu.
+       fun add_link(content: TplLink) do
+               var is_active = content.href == current_url
+               add_item(content, is_active)
+       end
 
        # Add a content between `<li>` tags
        fun add_item(content: Streamable, is_active: Bool) do
@@ -258,11 +274,11 @@ class TplSideBox
 
        # Content to display in the box
        # box will not be rendered if the content is null
-       var content: nullable Streamable writable
+       var content: nullable Streamable is writable
 
        # Is the box opened by default
        # otherwise, the user will have to clic on the title to display the content
-       var is_open writable = false
+       var is_open = false is writable
 
        init(title: String) do
                self.title = title
@@ -367,17 +383,23 @@ class TplSectionElt
        # Title to display if any
        # if both `title` and `summary_title` are null then
        # the section will not appear in the summary
-       var title: nullable Streamable writable
+       var title: nullable Streamable is writable
 
        # Subtitle to display if any
-       var subtitle: nullable Streamable writable
+       var subtitle: nullable Streamable is writable
 
        # Title that appear in the summary
        # if null use `title` instead
-       var summary_title: nullable String writable
+       var summary_title: nullable String is writable
+
+       # CSS classes to apply on the section element
+       var css_classes = new Array[String]
+
+       # CSS classes to apply on the title heading element
+       var title_classes = new Array[String]
 
-       # Parent section of this section if any
-       var parent: nullable TplSection
+       # Parent article/section if any
+       var parent: nullable TplSectionElt
 
        init(id: String) do self.id = id
 
@@ -392,17 +414,6 @@ class TplSectionElt
                return parent.hlvl + 1
        end
 
-       # Render this section in the summary
-       protected fun render_summary(parent: TplSummaryElt) is abstract
-
-       # Is the section empty (no content at all)
-       fun is_empty: Bool is abstract
-end
-
-# A HTML <section> element
-class TplSection
-       super TplSectionElt
-
        # Elements contained by this section
        var children = new Array[TplSectionElt]
 
@@ -412,9 +423,11 @@ class TplSection
                children.add child
        end
 
-       redef fun is_empty: Bool do return children.is_empty
+       # Is the section empty (no content at all)
+       fun is_empty: Bool do return children.is_empty
 
-       redef fun render_summary(parent) do
+       # Render this section in the summary
+       fun render_summary(parent: TplSummaryElt) do
                if is_empty then return
                var title = summary_title
                if title == null and self.title != null then title = self.title.write_to_string
@@ -426,12 +439,18 @@ class TplSection
                end
                parent.add_child entry
        end
+end
+
+# A HTML <section> element
+class TplSection
+       super TplSectionElt
 
        redef fun rendering do
-               add "<section id='{id}'>"
+               add "<section id='{id}' class='{css_classes.join(" ")}'>"
                if title != null then
                        var lvl = hlvl
-                       add "<h{lvl}>"
+                       if lvl == 2 then title_classes.add "well well-sm"
+                       add "<h{lvl} class='{title_classes.join(" ")}'>"
                        add title.as(not null)
                        add "</h{lvl}>"
                end
@@ -452,16 +471,14 @@ class TplArticle
        super TplSectionElt
 
        # Content for this article
-       var content: nullable Streamable writable = null
+       var content: nullable Streamable = null is writable
+       var source_link: nullable Streamable = null is writable
 
        init with_content(id: String, title: Streamable, content: Streamable) do
                with_title(id, title)
                self.content = content
        end
 
-       # CSS classes to apply on the article title heading element
-       var title_classes = new Array[String]
-
        redef fun render_summary(parent) do
                if is_empty then return
                var title = summary_title
@@ -473,9 +490,15 @@ class TplArticle
 
        redef fun rendering do
                if is_empty then return
-               add "<article id='{id}'>"
+               add "<article id='{id}' class='{css_classes.join(" ")}'>"
+               if source_link != null then
+                       add "<div class='source-link'>"
+                       add source_link.as(not null)
+                       add "</div>"
+               end
                if title != null then
                        var lvl = hlvl
+                       if lvl == 2 then title_classes.add "well well-sm"
                        add "<h{lvl} class='{title_classes.join(" ")}'>"
                        add title.as(not null)
                        add "</h{lvl}>"
@@ -488,11 +511,14 @@ class TplArticle
                if content != null then
                        add content.as(not null)
                end
+               for child in children do
+                       add child
+               end
                add """</article>"""
        end
 
        redef fun is_empty: Bool do
-               return title == null and subtitle == null and content == null
+               return title == null and subtitle == null and content == null and children.is_empty
        end
 end
 
@@ -501,22 +527,22 @@ class TplDefinition
        super Template
 
        # Comment to display
-       var comment: nullable Streamable writable
+       var comment: nullable Streamable = null is writable
 
        # Namespace for this definition
-       var namespace: Streamable writable
+       var namespace: nullable Streamable = null is writable
 
        # Location link to display
-       var location: nullable Streamable writable
-
-       init do end
+       var location: nullable Streamable = null is writable
 
        private fun render_info do
                add "<div class='info text-right'>"
-               if comment == null then
-                       add "<span class=\"noComment\">no comment for </span>"
+               if namespace != null then
+                       if comment == null then
+                               add "<span class=\"noComment\">no comment for </span>"
+                       end
+                       add namespace.as(not null)
                end
-               add namespace
                if location != null then
                        add " "
                        add location.as(not null)
@@ -572,6 +598,7 @@ class TplSearchPage
        var props = new Array[Streamable]
 
        redef fun rendering do
+               var title = self.title
                if title != null then add "<h1>{title}</h1>"
                add "<div class='container-fluid'>"
                add " <div class='row'>"
@@ -625,13 +652,13 @@ class TplLink
        super Template
 
        # Link href
-       var href: String writable
+       var href: String is writable
 
        # Text to display in the link
-       var text: String writable
+       var text: Streamable is writable
 
        # Optional title
-       var title: nullable String writable
+       var title: nullable String is writable
 
        init(href, text: String) do
                self.href = href
@@ -670,12 +697,14 @@ class TplList
        var css_classes = new Array[String]
 
        # Add content wrapped in a <li> element
-       fun add_li(content: Streamable) do elts.add new TplListItem.with_content(content)
+       fun add_li(item: TplListItem) do elts.add item
 
        init do end
 
        init with_classes(classes: Array[String]) do self.css_classes = classes
 
+       fun is_empty: Bool do return elts.is_empty
+
        redef fun rendering do
                if elts.is_empty then return
                add "<ul class='{css_classes.join(" ")}'>"
@@ -713,9 +742,7 @@ class TplListItem
        fun append(content: Streamable) do self.content.add content
 
        redef fun rendering do
-               add "<li class='"
-               for cls in css_classes do add " {cls}"
-               add "'>"
+               add "<li class='{css_classes.join(" ")}'>"
                add content
                add "</li>"
        end
@@ -726,12 +753,11 @@ class TplLabel
        super Template
 
        # Content of the label if any
-       var content: nullable Streamable
+       var content: nullable Streamable = null is writable
 
        # CSS classes of the <span> element
        var css_classes = new Array[String]
 
-       init do end
        init with_content(content: Streamable) do self.content = content
        init with_classes(classes: Array[String]) do self.css_classes = classes
 
@@ -773,6 +799,7 @@ class TagAttribute
        end
 
        redef fun rendering do
+               var value = self.value
                if value == null then
                        add(" {name}")
                else
@@ -786,7 +813,7 @@ class TplScript
        super Template
 
        var attrs = new Array[TagAttribute]
-       var content: nullable Streamable writable
+       var content: nullable Streamable = null is writable
 
        init do
                attrs.add(new TagAttribute("type", "text/javascript"))