nitdoc: auto hide source-link
[nit.git] / src / doc / doc_templates.nit
index 726e229..8962221 100644 (file)
@@ -376,8 +376,14 @@ class TplSectionElt
        # if null use `title` instead
        var summary_title: nullable String writable
 
-       # Parent section of this section if any
-       var parent: nullable TplSection
+       # 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 article/section if any
+       var parent: nullable TplSectionElt
 
        init(id: String) do self.id = id
 
@@ -392,17 +398,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 +407,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 +423,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
@@ -453,15 +456,13 @@ class TplArticle
 
        # Content for this article
        var content: nullable Streamable writable = null
+       var source_link: nullable Streamable writable = null
 
        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 +474,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,6 +495,9 @@ class TplArticle
                if content != null then
                        add content.as(not null)
                end
+               for child in children do
+                       add child
+               end
                add """</article>"""
        end
 
@@ -504,7 +514,7 @@ class TplDefinition
        var comment: nullable Streamable writable
 
        # Namespace for this definition
-       var namespace: Streamable writable
+       var namespace: nullable Streamable writable
 
        # Location link to display
        var location: nullable Streamable writable
@@ -513,10 +523,12 @@ class TplDefinition
 
        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)
@@ -676,6 +688,8 @@ class TplList
 
        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(" ")}'>"