nitdoc: move `DocComposite::toc_title` in `doc_base`
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 26 May 2015 21:04:00 +0000 (17:04 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 29 May 2015 23:05:55 +0000 (19:05 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_base.nit
src/doc/doc_phases/doc_html.nit
src/doc/doc_phases/doc_lin.nit
src/doc/html_templates/html_templates.nit

index f517955..e198e70 100644 (file)
@@ -124,6 +124,9 @@ abstract class DocComposite
        # Does `self` have `children`?
        fun is_empty: Bool do return children.is_empty
 
+       # Title used in table of content if any.
+       var toc_title: nullable String is writable, lazy do return title
+
        # Add a `child` to `self`.
        #
        # Shortcut for `children.add`.
index 4439e98..83a2cc9 100644 (file)
@@ -471,7 +471,7 @@ redef class MEntitySection
                        title.add mentity.html_signature
                        html_title = title
                        html_subtitle = mentity.html_namespace
-                       toc_title = mentity.html_name
+                       html_toc_title = mentity.html_name
                end
                super
        end
@@ -484,16 +484,16 @@ redef class ConcernSection
                var mentity = self.mentity
                if page isa MGroupPage then
                        html_title = null
-                       toc_title = mentity.html_name
+                       html_toc_title = mentity.html_name
                        is_toc_hidden = false
                else if page.mentity isa MModule and mentity isa MModule then
                        var title = new Template
                        if mentity == page.mentity then
                                title.add "in "
-                               toc_title = "in {mentity.html_name}"
+                               html_toc_title = "in {mentity.html_name}"
                        else
                                title.add "from "
-                               toc_title = "from {mentity.html_name}"
+                               html_toc_title = "from {mentity.html_name}"
                        end
                        title.add mentity.html_namespace
                        html_title = title
@@ -503,7 +503,7 @@ redef class ConcernSection
                        title.add "in "
                        title.add mentity.html_namespace
                        html_title = title
-                       toc_title = "in {mentity.html_name}"
+                       html_toc_title = "in {mentity.html_name}"
                end
                super
        end
@@ -532,7 +532,7 @@ redef class DefinitionArticle
                        title.add mentity.html_icon
                        title.add mentity.html_namespace
                        html_title = title
-                       toc_title = mentity.html_name
+                       html_toc_title = mentity.html_name
                        if mentity isa MModule then
                                html_source_link = v.html_source_link(mentity.location)
                        end
@@ -542,7 +542,7 @@ redef class DefinitionArticle
                        title.add mentity.mmodule.html_namespace
                        html_title = mentity.html_declaration
                        html_subtitle = title
-                       toc_title = "in {mentity.html_name}"
+                       html_toc_title = "in {mentity.html_name}"
                        html_source_link = v.html_source_link(mentity.location)
                        if page isa MEntityPage and mentity.is_intro and mentity.mmodule != page.mentity then
                                is_short_comment = true
@@ -555,13 +555,13 @@ redef class DefinitionArticle
                                title.add mentity.html_declaration
                                html_title = title
                                html_subtitle = mentity.html_namespace
-                               toc_title = mentity.html_name
+                               html_toc_title = mentity.html_name
                        else
                                var title = new Template
                                title.add "in "
                                title.add mentity.mclassdef.html_link
                                html_title = title
-                               toc_title = "in {mentity.mclassdef.html_name}"
+                               html_toc_title = "in {mentity.mclassdef.html_name}"
                        end
                        html_source_link = v.html_source_link(mentity.location)
                end
@@ -576,7 +576,7 @@ redef class HomeArticle
        redef fun init_html_render(v, doc, page) do
                if v.ctx.opt_custom_title.value != null then
                        self.html_title = v.ctx.opt_custom_title.value.to_s
-                       self.toc_title = v.ctx.opt_custom_title.value.to_s
+                       self.html_toc_title = v.ctx.opt_custom_title.value.to_s
                end
                self.content = v.ctx.opt_custom_intro.value
                super
index a919f93..647eaee 100644 (file)
@@ -97,4 +97,6 @@ class DefinitionLinArticle
 
        # The linearized list to display.
        var mentities: Array[MEntity]
+
+       redef var toc_title = "Linearization"
 end
index 9de02a9..1a5a17c 100644 (file)
@@ -294,7 +294,10 @@ redef class DocComposite
        # A short, undecorated title that goes in the table of contents.
        #
        # By default, returns `html_title.to_s`, subclasses should redefine it.
-       var toc_title: String is lazy, writable do return html_title.to_s
+       var html_toc_title: nullable String is lazy, writable do
+               if html_title == null then return toc_title
+               return html_title.write_to_string
+       end
 
        # Is `self` hidden in the table of content?
        var is_toc_hidden = false is writable
@@ -304,8 +307,7 @@ redef class DocComposite
                if is_toc_hidden then return
 
                var content = new Template
-               content.add new Link("#{html_id}", toc_title)
-
+               content.add new Link("#{html_id}", html_toc_title.to_s)
                if not children.is_empty then
                        var sublst = new UnorderedList
                        sublst.css_classes.add "nav"
@@ -365,7 +367,8 @@ redef class TabbedGroup
                var tabs = new DocTabs("{html_id}.tabs", "")
                for child in children do
                        if child.is_hidden then continue
-                       tabs.add_panel new DocTabPanel(child.html_tab_id, child.toc_title, child)
+                       var title = child.html_toc_title or else child.toc_title or else ""
+                       tabs.add_panel new DocTabPanel(child.html_tab_id, title, child)
                end
                addn tabs
        end
@@ -479,7 +482,8 @@ redef class IntroArticle
                end
                for child in children do
                        if child.is_hidden then continue
-                       tabs.add_panel new DocTabPanel(child.html_tab_id, child.toc_title, child)
+                       var title = child.html_toc_title or else child.toc_title or else ""
+                       tabs.add_panel new DocTabPanel(child.html_tab_id, title, child)
                end
                var lnk = html_source_link
                if lnk != null then
@@ -504,7 +508,7 @@ redef class DefinitionListArticle
        end
 
        redef var html_subtitle is lazy do return mentity.html_namespace
-       redef var toc_title is lazy do return mentity.html_name
+       redef var html_toc_title is lazy do return mentity.html_name
 end
 
 redef class DefinitionArticle
@@ -540,7 +544,8 @@ redef class DefinitionArticle
                end
                for child in children do
                        if child.is_hidden then continue
-                       tabs.add_panel new DocTabPanel(child.html_tab_id, child.toc_title, child)
+                       var title = child.html_toc_title or else child.toc_title or else ""
+                       tabs.add_panel new DocTabPanel(child.html_tab_id, title, child)
                end
                var lnk = html_source_link
                if lnk != null then
@@ -612,7 +617,6 @@ end
 
 redef class GraphArticle
        redef var html_title = null
-       redef var toc_title do return "Graph"
        redef var is_hidden = false
        redef var is_toc_hidden = true