Merge: nitdoc: refactoring and cleaning
authorJean Privat <jean@pryen.org>
Sat, 30 May 2015 00:36:30 +0000 (20:36 -0400)
committerJean Privat <jean@pryen.org>
Sat, 30 May 2015 00:36:30 +0000 (20:36 -0400)
Now that nitx and nitdoc are fully merged with the same structure and services, we can start the refactoring to limit the differences between both tools.

Note that the first four commits are from #1401.

Demos from [Jenkins::CI-nitdoc](http://gresil.org/jenkins/job/CI-nitdoc):
* [Standard library](http://gresil.org/jenkins/job/CI-nitdoc/ws/doc/stdlib/index.html)
* [Nit compilers and tools](http://gresil.org/jenkins/job/CI-nitdoc/ws/doc/nitc/index.html)

Pull-Request: #1416
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>

14 files changed:
share/nitdoc/css/nitdoc.css
src/doc/console_templates/console_templates.nit
src/doc/doc_base.nit
src/doc/doc_phases/doc_console.nit
src/doc/doc_phases/doc_graphs.nit
src/doc/doc_phases/doc_hierarchies.nit
src/doc/doc_phases/doc_html.nit
src/doc/doc_phases/doc_indexing.nit
src/doc/doc_phases/doc_intros_redefs.nit
src/doc/doc_phases/doc_lin.nit
src/doc/doc_phases/doc_poset.nit
src/doc/doc_phases/doc_structure.nit
src/doc/html_templates/html_model.nit
src/doc/html_templates/html_templates.nit

index e47f3aa..01da471 100644 (file)
@@ -81,9 +81,6 @@ article.nospace {
        color: #666;
 }
 
-#sidebar .panel-body ul .list-labeled>li {
-}
-
 #sidebar .panel-body ul ul ul>li {
        font-size: 13px;
        color: #999;
index 45bc33e..e94a388 100644 (file)
@@ -81,11 +81,6 @@ redef class ConcernSection
        end
 end
 
-redef class ConstructorsSection
-       redef var cs_title = "Constructors"
-       redef var cs_subtitle = null
-end
-
 redef class MEntityComposite
        redef var cs_title is lazy do return mentity.cs_name
        redef var cs_subtitle is lazy do return mentity.cs_namespace
index 8f0467d..4338eee 100644 (file)
@@ -75,6 +75,15 @@ class DocPage
        var root = new DocRoot
 
        redef fun to_s do return title
+
+       # Pretty prints the content of this page.
+       fun pretty_print: Writable do
+               var res = new Template
+               res.addn "page: {title}"
+               res.addn ""
+               root.pretty_print_in(res)
+               return res
+       end
 end
 
 # `DocPage` elements that can be nested in another.
@@ -91,6 +100,19 @@ abstract class DocComposite
        # Parent element.
        var parent: nullable DocComposite = null is writable
 
+       # Element uniq id.
+       #
+       # The `id` is used as name for the generated element (if any).
+       # Because multiple elements can be generated in the same container
+       # it should be uniq.
+       #
+       # The `id` can also be used to establish links between elements
+       # (HTML links, HTML anchors, vim links, etc.).
+       var id: String is writable
+
+       # Item title if any.
+       var title: nullable String
+
        # Does `self` have a `parent`?
        fun is_root: Bool do return parent == null
 
@@ -99,8 +121,18 @@ abstract class DocComposite
        # Children are ordered, this order can be changed by the `DocPhase`.
        var children = new Array[DocComposite]
 
-       # Does `self` have `children`?
-       fun is_empty: Bool do return children.is_empty
+       # Is `self` not displayed in the page.
+       #
+       # By default, empty elements are hidden.
+       fun is_hidden: 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
+
+       # Is `self` hidden in the table of content?
+       var is_toc_hidden: Bool is writable, lazy do
+               return toc_title == null or is_hidden
+       end
 
        # Add a `child` to `self`.
        #
@@ -115,6 +147,20 @@ abstract class DocComposite
                if parent == null then return 0
                return parent.depth + 1
        end
+
+       # Pretty prints this composite recursively.
+       fun pretty_print: Writable do
+               var res = new Template
+               pretty_print_in(res)
+               return res
+       end
+
+       # Appends the Pretty print of this composite in `res`.
+       private fun pretty_print_in(res: Template) do
+               res.add "#" * depth
+               res.addn " {id}"
+               for child in children do child.pretty_print_in(res)
+       end
 end
 
 # The `DocComposite` element that contains all the other.
@@ -122,8 +168,12 @@ end
 # The root uses a specific subclass to provide different a different behavior
 # than other `DocComposite` elements.
 class DocRoot
+       noautoinit
        super DocComposite
 
+       redef var id = "<root>"
+       redef var title = "<root>"
+
        # No op for `RootSection`.
        redef fun parent=(p) do end
 end
index f927fd9..4c0c193 100644 (file)
@@ -140,7 +140,7 @@ interface NitxQuery
        # Pretty prints the results for the console.
        fun make_results(nitx: Nitx, results: Array[NitxMatch]): DocPage do
                var page = new DocPage("results", "Results")
-               page.root.add_child(new QueryResultArticle(self, results))
+               page.root.add_child(new QueryResultArticle("results.article", "Results", self, results))
                return page
        end
 
@@ -215,8 +215,8 @@ class CommentQuery
                if len == 1 then
                        var res = results.first.as(MEntityMatch)
                        var mentity = res.mentity
-                       var page = new DocPage("resultats", "Results")
-                       var article = new DefinitionArticle(mentity)
+                       var page = new DocPage("results", "Results")
+                       var article = new DefinitionArticle("results.article", "Results", mentity)
                        article.cs_title = mentity.name
                        article.cs_subtitle = mentity.cs_declaration
                        page.root.add_child article
@@ -389,7 +389,7 @@ class CodeQuery
        redef fun make_results(nitx, results) do
                var page = new DocPage("results", "Code Results")
                for res in results do
-                       page.add new CodeQueryArticle(self, res.as(CodeMatch))
+                       page.add new CodeQueryArticle("results.article", "Results", self, res.as(CodeMatch))
                end
                return page
        end
index 1339d09..50a2aab 100644 (file)
@@ -73,7 +73,7 @@ redef class MModulePage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(mentity, name, "Importation Graph", op)
+               return new GraphArticle("{mentity.nitdoc_id}.graph", "Importation Graph", name, op)
        end
 end
 
@@ -107,7 +107,7 @@ redef class MClassPage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(mentity, name, "Inheritance Graph", op)
+               return new GraphArticle("{mentity.nitdoc_id}.graph", "Inheritance Graph", name, op)
        end
 end
 
@@ -116,16 +116,14 @@ end
 # The graph is stored in dot format.
 # The final output is delayed untill rendering.
 class GraphArticle
-       super MEntityComposite
+       super DocArticle
 
        # Graph ID (used for outputing file with names).
-       var id: String
-
-       # Graph title to display.
-       var graph_title: String
+       var graph_id: String
 
        # Dot script of the graph.
        var dot: Text
 
-       redef var is_empty = false
+       redef var is_hidden = false
+       redef var is_toc_hidden = true
 end
index eecc95b..fa9de2d 100644 (file)
@@ -40,14 +40,15 @@ end
 
 redef class MModulePage
        redef fun build_inh_list(v, doc) do
-               var section = new ImportationListSection(mentity)
-               var group = new PanelGroup("List")
+               var id = mentity.nitdoc_id
+               var section = new TabbedGroup("{id}.importation", "Dependencies")
+               var group = new PanelGroup("list.group", "List")
                var imports = self.imports.to_a
                v.name_sorter.sort(imports)
-               group.add_child new HierarchyListArticle(mentity, "Imports", imports)
+               group.add_child new MEntitiesListArticle("{id}.imports", "Imports", imports)
                var clients = self.clients.to_a
                v.name_sorter.sort(clients)
-               group.add_child new HierarchyListArticle(mentity, "Clients", clients)
+               group.add_child new MEntitiesListArticle("{id}.clients", "Clients", clients)
                section.add_child group
                section.parent = root.children.first
                root.children.first.children.insert(section, 1)
@@ -56,45 +57,23 @@ end
 
 redef class MClassPage
        redef fun build_inh_list(v, doc) do
-               var section = new InheritanceListSection(mentity)
-               var group = new PanelGroup("List")
+               var id = mentity.nitdoc_id
+               var section = new TabbedGroup("{id}.inheritance", "Inheritance")
+               var group = new PanelGroup("list.group", "List")
                var parents = self.parents.to_a
                v.name_sorter.sort(parents)
-               group.add_child new HierarchyListArticle(mentity, "Parents", parents)
+               group.add_child new MEntitiesListArticle("{id}.parents", "Parents", parents)
                var ancestors = self.ancestors.to_a
                v.name_sorter.sort(ancestors)
-               group.add_child new HierarchyListArticle(mentity, "Ancestors", ancestors)
+               group.add_child new MEntitiesListArticle("{id}.ancestors", "Ancestors", ancestors)
                var children = self.children.to_a
                v.name_sorter.sort(children)
-               group.add_child new HierarchyListArticle(mentity, "Children", children)
+               group.add_child new MEntitiesListArticle("{id}.children", "Children", children)
                var descendants = self.descendants.to_a
                v.name_sorter.sort(descendants)
-               group.add_child new HierarchyListArticle(mentity, "Descendants", descendants)
+               group.add_child new MEntitiesListArticle("{id}.descendants", "Descendants", descendants)
                section.add_child group
                section.parent = root.children.first
                root.children.first.children.insert(section, 1)
        end
 end
-
-# FIXME diff hack
-class ImportationListSection
-       super TabbedGroup
-       super MEntityComposite
-end
-
-# FIXME diff hack
-class InheritanceListSection
-       super TabbedGroup
-       super MEntityComposite
-end
-
-# Dislay a hierarchical list of mentities.
-class HierarchyListArticle
-       super MEntityArticle
-
-       # Title displayed in the top of this list.
-       var list_title: String
-
-       # MEntities to display in this list.
-       var mentities: Array[MEntity]
-end
index 0c843bb..83a2cc9 100644 (file)
@@ -372,7 +372,7 @@ redef class MClassPage
                if not mprop_is_local(mprop) then
                        classes.add "inherit"
                        var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url
-                       var def_url = "{cls_url}#article:{mprop.nitdoc_id}.definition"
+                       var def_url = "{cls_url}#{mprop.nitdoc_id}.definition"
                        var lnk = new Link(def_url, mprop.html_name)
                        var mdoc = mprop.intro.mdoc_or_fallback
                        if mdoc != null then lnk.title = mdoc.short_comment
@@ -388,7 +388,7 @@ redef class MClassPage
                end
                var def = select_mpropdef(mprop)
                var anc = def.html_link_to_anchor
-               anc.href = "#article:{def.nitdoc_id}.definition"
+               anc.href = "#{def.nitdoc_id}.definition"
                var lnk = new Template
                lnk.add new DocHTMLLabel.with_classes(classes)
                lnk.add anc
@@ -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
@@ -586,7 +586,7 @@ end
 redef class GraphArticle
        redef fun init_html_render(v, doc, page) do
                var output_dir = v.ctx.output_dir
-               var path = output_dir / id
+               var path = output_dir / graph_id
                var path_sh = path.escape_to_sh
                var file = new FileWriter.open("{path}.dot")
                file.write(dot)
index 72df73c..1e74138 100644 (file)
@@ -43,7 +43,7 @@ class IndexingPhase
                                if not doc.mpropdefs.has(mpropdef) then continue
                                var full_name = mpropdef.mclassdef.mclass.full_name
                                var cls_url = mpropdef.mclassdef.mclass.nitdoc_url
-                               var def_url = "{cls_url}#article:{mpropdef.nitdoc_id}.definition"
+                               var def_url = "{cls_url}#{mpropdef.nitdoc_id}.definition"
                                add_result_for(mproperty.name, full_name, def_url)
                        end
                end
index 5ed6f78..ae341f9 100644 (file)
@@ -54,52 +54,33 @@ redef class DefinitionArticle
 
        # TODO this should move to MEntity?
        private fun build_mmodule_list(v: IntroRedefListPhase, doc: DocModel, mmodule: MModule) do
-               var section = new IntrosRedefsSection(mentity)
-               var group = new PanelGroup("List")
+               var section = new TabbedGroup("{mentity.nitdoc_id}.intros_redefs")
+               section.toc_title = "Intros / Redefs"
+               var group = new PanelGroup("list.group", "List")
                var intros = mmodule.intro_mclassdefs(v.ctx.min_visibility).to_a
                doc.mainmodule.linearize_mclassdefs(intros)
-               group.add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
+               group.add_child new MEntitiesListArticle("{mentity.nitdoc_id}.intros", "Introduces", intros)
                var redefs = mmodule.redef_mclassdefs(v.ctx.min_visibility).to_a
                doc.mainmodule.linearize_mclassdefs(redefs)
-               group.add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+               group.add_child new MEntitiesListArticle("{mentity.nitdoc_id}.redefs", "Redefines", redefs)
                section.add_child group
                add_child(section)
        end
 
        # TODO this should move to MEntity?
        private fun build_mclassdef_list(v: IntroRedefListPhase, doc: DocModel, mclassdef: MClassDef) do
-               var section = new IntrosRedefsSection(mentity)
-               var group = new PanelGroup("List")
+               var section = new TabbedGroup("{mentity.nitdoc_id}.intros_redefs")
+               section.toc_title = "Intros / Redefs"
+               var group = new PanelGroup("list.group", "List")
                var intros = mclassdef.collect_intro_mpropdefs(v.ctx.min_visibility).to_a
                # FIXME avoid diff changes
                # v.ctx.mainmodule.linearize_mpropdefs(intros)
-               group.add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
+               group.add_child new MEntitiesListArticle("{mentity.nitdoc_id}.intros", "Introduces", intros)
                var redefs = mclassdef.collect_redef_mpropdefs(v.ctx.min_visibility).to_a
                # FIXME avoid diff changes
                # v.ctx.mainmodule.linearize_mpropdefs(redefs)
-               group.add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+               group.add_child new MEntitiesListArticle("{mentity.nitdoc_id}.redefs", "Redefines", redefs)
                section.add_child group
                add_child(section)
        end
-
-end
-
-# Section that contains the intros and redefs lists.
-class IntrosRedefsSection
-       super TabbedGroup
-       super MEntitySection
-end
-
-# An article that displays a list of introduced / refined mentities.
-#
-# FIXME diff hack
-# This can merged with InheritanceListArticle in a more generic class.
-class IntrosRedefsListArticle
-       super MEntityArticle
-
-       # Title displayed as header of the list.
-       var list_title: String
-
-       # Intro mentities to list.
-       var mentities: Array[MEntity]
 end
index c36756c..7864b27 100644 (file)
@@ -73,7 +73,7 @@ redef class DefinitionArticle
                var lin = all_defs.to_a
                doc.mainmodule.linearize_mpropdefs(lin)
                if lin.length > 1 then
-                       add_child new DefinitionLinArticle(mentity, lin)
+                       add_child new DefinitionLinArticle("{mentity.nitdoc_id}.lin", "Linearization", lin)
                end
        end
 
@@ -93,8 +93,11 @@ end
 
 # Display a linearized list of definitions.
 class DefinitionLinArticle
-       super MEntityArticle
+       super DocArticle
 
        # The linearized list to display.
        var mentities: Array[MEntity]
+
+       redef fun is_hidden do return mentities.is_empty
+       redef var is_toc_hidden = true
 end
index 0c610d4..556733e 100644 (file)
@@ -46,7 +46,7 @@ redef class MModulePage
        # Imported modules that should appear in the documentation.
        var imports = new HashSet[MModule]
 
-       # Clients modules that shjould appear in the documentation.
+       # Clients modules that should appear in the documentation.
        var clients = new HashSet[MModule]
 
        redef fun build_poset(v, doc) do
index 7491e4b..f9824d3 100644 (file)
@@ -47,15 +47,15 @@ end
 
 redef class OverviewPage
        redef fun apply_structure(v, doc) do
-               var article = new HomeArticle
+               var article = new HomeArticle("home.article", "Home")
                root.add_child article
                # Projects list
                var mprojects = doc.model.mprojects.to_a
                var sorter = new MConcernRankSorter
                sorter.sort mprojects
-               var section = new ProjectsSection
+               var section = new DocSection("projects.section", "Projects")
                for mproject in mprojects do
-                       section.add_child new DefinitionArticle(mproject)
+                       section.add_child new DefinitionArticle("{mproject.nitdoc_id}.definition", mproject)
                end
                article.add_child section
        end
@@ -69,18 +69,18 @@ redef class SearchPage
                v.name_sorter.sort(mclasses)
                var mprops = doc.mproperties.to_a
                v.name_sorter.sort(mprops)
-               root.add_child new IndexArticle(mmodules, mclasses, mprops)
+               root.add_child new IndexArticle("index.article", mmodules, mclasses, mprops)
        end
 end
 
 redef class MGroupPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
                root.add_child section
                if mentity.is_root then
-                       section.add_child new IntroArticle(mentity.mproject)
+                       section.add_child new IntroArticle("{mentity.mproject.nitdoc_id}.intro", mentity.mproject)
                else
-                       section.add_child new IntroArticle(mentity)
+                       section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
                end
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
@@ -90,11 +90,11 @@ redef class MGroupPage
                concerns.sort_with(v.concerns_sorter)
                mentity.mproject.booster_rank = 0
                mentity.booster_rank = 0
-               section.add_child new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
                        if mentity isa MModule then
-                               ssection.add_child new DefinitionArticle(mentity)
+                               ssection.add_child new DefinitionArticle("{mentity.nitdoc_id}.definition", mentity)
                        end
                        section.add_child ssection
                end
@@ -103,9 +103,9 @@ end
 
 redef class MModulePage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME avoid diff
@@ -116,22 +116,25 @@ redef class MModulePage
                mentity.mgroup.mproject.booster_rank = 0
                mentity.mgroup.booster_rank = 0
                mentity.booster_rank = 0
-               section.add_child new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
                # reference list
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
                        if mentity isa MModule then
                                var mclasses = mclasses_for_mmodule(mentity).to_a
                                v.name_sorter.sort(mclasses)
                                for mclass in mclasses do
-                                       var article = new DefinitionListArticle(mclass)
+                                       var article = new DefinitionListArticle(
+                                               "{mclass.intro.nitdoc_id}.definition-list", mclass)
                                        var mclassdefs = mclassdefs_for(mclass).to_a
                                        if not mclassdefs.has(mclass.intro) then
-                                               article.add_child(new DefinitionArticle(mclass.intro))
+                                               article.add_child(new DefinitionArticle(
+                                                       "{mclass.intro.nitdoc_id}.definition", mclass.intro))
                                        end
                                        doc.mainmodule.linearize_mclassdefs(mclassdefs)
                                        for mclassdef in mclassdefs do
-                                               article.add_child(new DefinitionArticle(mclassdef))
+                                               article.add_child(new DefinitionArticle(
+                                                       "{mclassdef.nitdoc_id}.definition", mclassdef))
                                        end
                                        ssection.add_child article
                                end
@@ -165,9 +168,9 @@ end
 
 redef class MClassPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -178,15 +181,15 @@ redef class MClassPage
                mentity.intro_mmodule.mgroup.mproject.booster_rank = 0
                mentity.intro_mmodule.mgroup.booster_rank = 0
                mentity.intro_mmodule.booster_rank = 0
-               var constructors = new ConstructorsSection(mentity)
+               var constructors = new DocSection("{mentity.nitdoc_id}.constructors", "Constructors")
                var minit = mentity.root_init
                if minit != null then
-                       constructors.add_child new DefinitionArticle(minit)
+                       constructors.add_child new DefinitionArticle("{minit.nitdoc_id}.definition", minit)
                end
                section.add_child constructors
-               section.add_child new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
                        if mentity isa MModule then
                                var mprops = mproperties_for(mentity)
                                var by_kind = new PropertiesByKind.with_elements(mprops)
@@ -196,9 +199,11 @@ redef class MClassPage
                                                for mpropdef in mpropdefs_for(mprop, mentity) do
                                                        if mpropdef isa MMethodDef and mpropdef.mproperty.is_init then
                                                                if mpropdef == minit then continue
-                                                               constructors.add_child new DefinitionArticle(mpropdef)
+                                                               constructors.add_child new DefinitionArticle(
+                                                                       "{mpropdef.nitdoc_id}.definition", mpropdef)
                                                        else
-                                                               ssection.add_child new DefinitionArticle(mpropdef)
+                                                               ssection.add_child new DefinitionArticle(
+                                                                       "{mpropdef.nitdoc_id}.definition", mpropdef)
                                                        end
                                                end
                                        end
@@ -238,9 +243,9 @@ end
 
 redef class MPropertyPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -251,15 +256,16 @@ redef class MPropertyPage
                mentity.intro.mclassdef.mmodule.mgroup.mproject.booster_rank = 0
                mentity.intro.mclassdef.mmodule.mgroup.booster_rank = 0
                mentity.intro.mclassdef.mmodule.booster_rank = 0
-               section.add_child new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
                        if mentity isa MModule then
                                # Add mproperties
                                var mpropdefs = mpropdefs_for(mentity).to_a
                                v.name_sorter.sort(mpropdefs)
                                for mpropdef in mpropdefs do
-                                       ssection.add_child new DefinitionArticle(mpropdef)
+                                       ssection.add_child new DefinitionArticle(
+                                               "{mpropdef.nitdoc_id}.definition", mpropdef)
                                end
                        end
                        section.add_child ssection
@@ -288,30 +294,26 @@ end
 # A group of sections that can be displayed together in a tab panel.
 class PanelGroup
        super DocSection
-
-       # The title of this group.
-       var group_title: String
 end
 
 # A DocComposite element about a MEntity.
 class MEntityComposite
        super DocComposite
 
+       redef fun title do return mentity.nitdoc_name
+
        # MEntity documented by this page element.
        var mentity: MEntity
 end
 
-# A list of constructors.
-class ConstructorsSection
-       super MEntitySection
-end
-
 # A Section about a Concern.
 #
 # Those sections are used to build the page summary.
 class ConcernSection
        super MEntityComposite
        super DocSection
+
+       redef fun is_toc_hidden do return is_hidden
 end
 
 # An article about a Mentity.
@@ -322,6 +324,17 @@ abstract class MEntityArticle
        super DocArticle
 end
 
+# An article that displays a list of mentities.
+class MEntitiesListArticle
+       super DocArticle
+
+       # MEntities to display.
+       var mentities: Array[MEntity]
+
+       redef fun is_hidden do return mentities.is_empty
+end
+
+
 # A section about a Mentity.
 #
 # Used to regroup content about a MEntity.
@@ -336,6 +349,9 @@ end
 class IntroArticle
        super MEntityComposite
        super DocArticle
+
+       redef var is_hidden = false
+       redef var is_toc_hidden = true
 end
 
 # An article that display a ConcernsTreee as a list.
@@ -344,9 +360,11 @@ class ConcernsArticle
 
        # Concerns to list in this article.
        var concerns: ConcernsTree
+
+       redef fun is_hidden do return concerns.is_empty
 end
 
-# An article that displaus a list of definition belonging to a MEntity.
+# An article that displays a list of definition belonging to a MEntity.
 class DefinitionListArticle
        super TabbedGroup
        super MEntityArticle
@@ -355,6 +373,8 @@ end
 # An article that display the definition text of a MEntity.
 class DefinitionArticle
        super MEntityArticle
+
+       redef var is_hidden = false
 end
 
 # The main project article.
@@ -362,11 +382,6 @@ class HomeArticle
        super DocArticle
 end
 
-# The project list.
-class ProjectsSection
-       super DocArticle
-end
-
 # An article that display an index of mmodules, mclasses and mproperties.
 class IndexArticle
        super DocArticle
@@ -379,4 +394,8 @@ class IndexArticle
 
        # List of mproperties to display.
        var mprops: Array[MProperty]
+
+       redef fun is_hidden do
+               return mmodules.is_empty and mclasses.is_empty and mprops.is_empty
+       end
 end
index bc8ccbe..46953d9 100644 (file)
@@ -686,7 +686,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("#concern:{nitdoc_id}", lnk.text, lnk.title)
+               tpl.add new Link.with_title("#{nitdoc_id}.concern", lnk.text, lnk.title)
                var comment = html_short_comment
                if comment != null then
                        tpl.add ": "
index ed680f0..8849fb3 100644 (file)
@@ -247,12 +247,12 @@ redef class DocComposite
        super Template
 
        # HTML anchor id
-       var html_id: String is noinit, writable
+       var html_id: String is writable, lazy do return id
 
        # Title to display if any.
        #
        # This title can be decorated with HTML.
-       var html_title: nullable Writable is noinit, writable
+       var html_title: nullable Writable is writable, lazy do return title
 
        # Subtitle to display if any.
        var html_subtitle: nullable Writable is noinit, writable
@@ -286,26 +286,20 @@ redef class DocComposite
        # Level <hX> for HTML heading.
        private fun hlvl: Int do return depth
 
-       # Is `self` not displayed in the page.
-       #
-       # By default, empty elements are hidden.
-       fun is_hidden: Bool do return is_empty
-
        # 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
-
-       # Is `self` hidden in the table of content?
-       var is_toc_hidden = false is writable
+       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
 
        # Render this element in a table of contents.
        private fun render_toc_item(lst: UnorderedList) do
-               if is_toc_hidden then return
+               if is_toc_hidden or html_toc_title == null 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"
@@ -327,6 +321,12 @@ redef class DocComposite
        end
 end
 
+redef class DocRoot
+       redef fun rendering do
+               for child in children do addn child.write_to_string
+       end
+end
+
 redef class DocSection
        super BSComponent
 
@@ -359,21 +359,20 @@ 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
 end
 
 redef class PanelGroup
-       redef var html_id is lazy do return "group:{group_title.to_lower.to_snake_case}"
        redef var html_title = null
-       redef var toc_title is lazy do return group_title
+       redef var toc_title is lazy do return title or else ""
        redef var is_toc_hidden = true
 end
 
 redef class HomeArticle
-       redef var html_id = "article:home"
        redef var html_title = "Overview"
 
        # HTML content to display on the home page.
@@ -389,11 +388,7 @@ redef class HomeArticle
 end
 
 redef class IndexArticle
-       redef var html_id = "article:index"
        redef var html_title = "Index"
-       redef fun is_empty do
-               return mmodules.is_empty and mclasses.is_empty and mprops.is_empty
-       end
 
        redef fun render_body do
                addn "<div class='container-fluid'>"
@@ -428,50 +423,21 @@ redef class IndexArticle
        end
 end
 
-redef class ProjectsSection
-       redef var html_id = "section:projects"
-       redef var html_title = "Projects"
-end
-
 redef class MEntityComposite
-       redef var html_id is lazy do return mentity.nitdoc_id
        redef var html_title is lazy do return mentity.nitdoc_name
 end
 
 redef class MEntitySection
-       redef var html_id is lazy do return "section:{mentity.nitdoc_name}"
        redef var html_title is lazy do return mentity.html_name
        redef var html_subtitle is lazy do return mentity.html_declaration
 end
 
-redef class ConstructorsSection
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.constructors"
-       redef var html_title = "Constructors"
-       redef var html_subtitle = null
-       redef fun is_toc_hidden do return is_empty
-end
-
 redef class ConcernSection
-       redef var html_id is lazy do return "concern:{mentity.nitdoc_id}"
        redef var html_title is lazy do return "in {mentity.nitdoc_name}"
-       redef fun is_toc_hidden do return is_empty
-end
-
-redef class ImportationListSection
-       redef var html_id is lazy do return "section:{mentity.nitdoc_id}.importation"
-       redef var html_title is lazy do return "Dependencies"
-end
-
-redef class InheritanceListSection
-       redef var html_id is lazy do return "section:{mentity.nitdoc_id}.inheritance"
-       redef var html_title is lazy do return "Inheritance"
 end
 
 redef class IntroArticle
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.intro"
        redef var html_title = null
-       redef var is_hidden = false
-       redef var is_toc_hidden = true
 
        # Link to source to display if any.
        var html_source_link: nullable Writable is noinit, writable
@@ -484,7 +450,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
@@ -495,15 +462,11 @@ redef class IntroArticle
 end
 
 redef class ConcernsArticle
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.concerns"
        redef var html_title = "Concerns"
-       redef fun is_hidden do return concerns.is_empty
        redef fun render_body do add concerns.html_list
 end
 
 redef class DefinitionListArticle
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.definition-list"
-
        redef var html_title is lazy do
                var title = new Template
                title.add mentity.html_icon
@@ -512,14 +475,12 @@ 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
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.definition"
        redef var html_title is lazy do return mentity.html_name
        redef var html_subtitle is lazy do return mentity.html_declaration
-       redef var is_hidden = false
 
        # Does `self` display only it's title and no body?
        #
@@ -549,7 +510,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
@@ -559,52 +521,18 @@ redef class DefinitionArticle
        end
 end
 
-redef class HierarchyListArticle
-       redef var html_id is lazy do return "article:{list_title}_{mentity.nitdoc_id}.hierarchy"
-       redef var html_title is lazy do return list_title
-       redef fun is_empty do return mentities.is_empty
-       redef var is_toc_hidden = true
-
+redef class MEntitiesListArticle
        redef fun render_body do
                var lst = new UnorderedList
                lst.css_classes.add "list-unstyled list-definition"
                for mentity in mentities do
                        lst.add_li mentity.html_list_item
                end
-               addn lst
-       end
-end
-
-redef class IntrosRedefsSection
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.intros_redefs"
-       redef var toc_title do return "Intros / Redefs"
-       redef var html_title = null
-       redef var html_subtitle = null
-       redef var is_toc_hidden = true
-end
-
-redef class IntrosRedefsListArticle
-       redef var html_id is lazy do return "article:{list_title}_{mentity.nitdoc_id}.intros_redefs"
-       redef var html_title is lazy do return list_title
-       redef fun is_hidden do return mentities.is_empty
-       redef var is_toc_hidden = true
-
-       redef fun render_body do
-               var lst = new UnorderedList
-               lst.css_classes.add "list-unstyled list-labeled"
-               for mentity in mentities do
-                       lst.add_li mentity.html_list_item
-               end
                add lst
        end
 end
 
 redef class DefinitionLinArticle
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.lin"
-       redef var html_title is lazy do return "Linearization"
-       redef fun is_hidden do return mentities.is_empty
-       redef var is_toc_hidden = true
-
        redef fun render_body do
                var lst = new UnorderedList
                lst.css_classes.add "list-unstyled list-labeled"
@@ -626,11 +554,7 @@ redef class DefinitionLinArticle
 end
 
 redef class GraphArticle
-       redef var html_id is lazy do return "article:{mentity.nitdoc_id}.graph"
        redef var html_title = null
-       redef var toc_title do return "Graph"
-       redef var is_hidden = false
-       redef var is_toc_hidden = true
 
        # HTML map used to display link.
        #
@@ -639,8 +563,8 @@ redef class GraphArticle
 
        redef fun render_body do
                addn "<div class=\"text-center\">"
-               addn " <img src='{id}.png' usemap='#{id}' style='margin:auto'"
-               addn "  alt='{graph_title}'/>"
+               addn " <img src='{graph_id}.png' usemap='#{graph_id}' style='margin:auto'"
+               addn "  alt='{title or else ""}'/>"
                add map
                addn "</div>"
        end