nitdoc: move `DocComposite::id` to `doc_base`
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 29 May 2015 23:02:35 +0000 (19:02 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 29 May 2015 23:02:35 +0000 (19:02 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

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_intros_redefs.nit
src/doc/doc_phases/doc_lin.nit
src/doc/doc_phases/doc_structure.nit
src/doc/html_templates/html_templates.nit

index 8f0467d..124ccce 100644 (file)
@@ -91,6 +91,16 @@ 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
+
        # Does `self` have a `parent`?
        fun is_root: Bool do return parent == null
 
@@ -122,8 +132,10 @@ 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>"
        # No op for `RootSection`.
        redef fun parent=(p) do end
 end
index f927fd9..7acdf10 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", 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", 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", self, res.as(CodeMatch))
                end
                return page
        end
index 1339d09..6552739 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("article:{mentity.nitdoc_id}.graph", mentity, name, "Importation Graph", 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("article:{mentity.nitdoc_id}.graph", mentity, name, "Inheritance Graph", op)
        end
 end
 
@@ -119,7 +119,7 @@ class GraphArticle
        super MEntityComposite
 
        # Graph ID (used for outputing file with names).
-       var id: String
+       var graph_id: String
 
        # Graph title to display.
        var graph_title: String
index eecc95b..9833dbd 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 ImportationListSection("section:{id}.importation", mentity)
+               var group = new PanelGroup("group:list", "List")
                var imports = self.imports.to_a
                v.name_sorter.sort(imports)
-               group.add_child new HierarchyListArticle(mentity, "Imports", imports)
+               group.add_child new HierarchyListArticle("article:Imports_{id}.hierarchy", mentity, "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 HierarchyListArticle("article:Clients_{id}.hierarchy", mentity, "Clients", clients)
                section.add_child group
                section.parent = root.children.first
                root.children.first.children.insert(section, 1)
@@ -56,20 +57,21 @@ 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 InheritanceListSection("section:{id}.inheritance", mentity)
+               var group = new PanelGroup("group:list", "List")
                var parents = self.parents.to_a
                v.name_sorter.sort(parents)
-               group.add_child new HierarchyListArticle(mentity, "Parents", parents)
+               group.add_child new HierarchyListArticle("article:Parents_{id}.hierarchy", mentity, "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 HierarchyListArticle("article:Ancestors_{id}.hierarchy", mentity, "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 HierarchyListArticle("article:Children_{id}.hierarchy", mentity, "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 HierarchyListArticle("article:Descendants_{id}.hierarchy", mentity, "Descendants", descendants)
                section.add_child group
                section.parent = root.children.first
                root.children.first.children.insert(section, 1)
index 0c843bb..c6a7ca1 100644 (file)
@@ -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 5ed6f78..eb3f0a6 100644 (file)
@@ -54,30 +54,30 @@ 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 IntrosRedefsSection("article:{mentity.nitdoc_id}.intros_redefs", mentity)
+               var group = new PanelGroup("group:list", "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 IntrosRedefsListArticle("article:Introduces_{mentity.nitdoc_id}.intros_redefs", mentity, "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 IntrosRedefsListArticle("article:Redefines_{mentity.nitdoc_id}.intros_redefs", mentity, "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 IntrosRedefsSection("article:{mentity.nitdoc_id}.intros_redefs", mentity)
+               var group = new PanelGroup("group:list", "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 IntrosRedefsListArticle("article:Introduces_{mentity.nitdoc_id}.intros_redefs", mentity, "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 IntrosRedefsListArticle("article:Redefines_{mentity.nitdoc_id}.intros_redefs", mentity, "Redefines", redefs)
                section.add_child group
                add_child(section)
        end
index c36756c..a57c71c 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("article:{mentity.nitdoc_id}.lin", mentity, lin)
                end
        end
 
index 7491e4b..c173408 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("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 ProjectsSection("section:projects")
                for mproject in mprojects do
-                       section.add_child new DefinitionArticle(mproject)
+                       section.add_child new DefinitionArticle("article:{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("article:index", mmodules, mclasses, mprops)
        end
 end
 
 redef class MGroupPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("section:{mentity.nitdoc_name}", mentity)
                root.add_child section
                if mentity.is_root then
-                       section.add_child new IntroArticle(mentity.mproject)
+                       section.add_child new IntroArticle("article:{mentity.mproject.nitdoc_id}.intro", mentity.mproject)
                else
-                       section.add_child new IntroArticle(mentity)
+                       section.add_child new IntroArticle("article:{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("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("concern:{mentity.nitdoc_id}", mentity)
                        if mentity isa MModule then
-                               ssection.add_child new DefinitionArticle(mentity)
+                               ssection.add_child new DefinitionArticle("article:{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("section:{mentity.nitdoc_name}", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("article:{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("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                # reference list
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("concern:{mentity.nitdoc_id}", 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(
+                                               "article:{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(
+                                                       "article:{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(
+                                                       "article:{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("section:{mentity.nitdoc_name}", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("article:{mentity.nitdoc_id}.intro", mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -178,15 +181,16 @@ 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 ConstructorsSection(
+                       "article:{mentity.nitdoc_id}.constructors", mentity)
                var minit = mentity.root_init
                if minit != null then
-                       constructors.add_child new DefinitionArticle(minit)
+                       constructors.add_child new DefinitionArticle("article:{minit.nitdoc_id}.definition", minit)
                end
                section.add_child constructors
-               section.add_child new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("concern:{mentity.nitdoc_id}", mentity)
                        if mentity isa MModule then
                                var mprops = mproperties_for(mentity)
                                var by_kind = new PropertiesByKind.with_elements(mprops)
@@ -196,9 +200,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(
+                                                                       "article:{mpropdef.nitdoc_id}.definition", mpropdef)
                                                        else
-                                                               ssection.add_child new DefinitionArticle(mpropdef)
+                                                               ssection.add_child new DefinitionArticle(
+                                                                       "article:{mpropdef.nitdoc_id}.definition", mpropdef)
                                                        end
                                                end
                                        end
@@ -238,9 +244,9 @@ end
 
 redef class MPropertyPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection(mentity)
+               var section = new MEntitySection("section:{mentity.nitdoc_name}", mentity)
                root.add_child section
-               section.add_child new IntroArticle(mentity)
+               section.add_child new IntroArticle("article:{mentity.nitdoc_id}.intro", mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -251,15 +257,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("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection(mentity)
+                       var ssection = new ConcernSection("concern:{mentity.nitdoc_id}", 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(
+                                               "article:{mpropdef.nitdoc_id}.definition", mpropdef)
                                end
                        end
                        section.add_child ssection
index ed680f0..031ae01 100644 (file)
@@ -247,7 +247,7 @@ 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.
        #
@@ -366,14 +366,12 @@ redef class TabbedGroup
 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 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,7 +387,6 @@ 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
@@ -429,46 +426,38 @@ redef class IndexArticle
 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
@@ -495,15 +484,12 @@ 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
@@ -516,7 +502,6 @@ redef class DefinitionListArticle
 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
@@ -560,7 +545,6 @@ redef class DefinitionArticle
 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
@@ -576,7 +560,6 @@ redef class HierarchyListArticle
 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
@@ -584,7 +567,6 @@ redef class IntrosRedefsSection
 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
@@ -600,7 +582,6 @@ redef class IntrosRedefsListArticle
 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
@@ -626,7 +607,6 @@ 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
@@ -639,7 +619,7 @@ redef class GraphArticle
 
        redef fun render_body do
                addn "<div class=\"text-center\">"
-               addn " <img src='{id}.png' usemap='#{id}' style='margin:auto'"
+               addn " <img src='{graph_id}.png' usemap='#{graph_id}' style='margin:auto'"
                addn "  alt='{graph_title}'/>"
                add map
                addn "</div>"