nitdoc: move `DocComposite::id` to `doc_base`
[nit.git] / src / doc / doc_phases / doc_structure.nit
index 6fc7468..c173408 100644 (file)
@@ -16,6 +16,7 @@
 module doc_structure
 
 import doc_concerns
+import modelize
 
 # StructurePhase populates the DocPage content with section and article.
 #
@@ -32,15 +33,11 @@ class StructurePhase
 
        # Populates the given DocModel.
        redef fun apply do
-               for page in doc.pages do
-                       if page isa MEntityPage then page.apply_structure(self, doc)
-               end
+               for page in doc.pages.values do page.apply_structure(self, doc)
        end
-
-       # TODO index and search page should also be structured here
 end
 
-redef class MEntityPage
+redef class DocPage
 
        # Populates `self` with structure elements like DocComposite ones.
        #
@@ -48,12 +45,42 @@ redef class MEntityPage
        fun apply_structure(v: StructurePhase, doc: DocModel) do end
 end
 
+redef class OverviewPage
+       redef fun apply_structure(v, doc) do
+               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("section:projects")
+               for mproject in mprojects do
+                       section.add_child new DefinitionArticle("article:{mproject.nitdoc_id}.definition", mproject)
+               end
+               article.add_child section
+       end
+end
+
+redef class SearchPage
+       redef fun apply_structure(v, doc) do
+               var mmodules = doc.mmodules.to_a
+               v.name_sorter.sort(mmodules)
+               var mclasses = doc.mclasses.to_a
+               v.name_sorter.sort(mclasses)
+               var mprops = doc.mproperties.to_a
+               v.name_sorter.sort(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("section:{mentity.nitdoc_name}", mentity)
+               root.add_child section
                if mentity.is_root then
-                       root.add new IntroArticle(mentity.mproject)
+                       section.add_child new IntroArticle("article:{mentity.mproject.nitdoc_id}.intro", mentity.mproject)
                else
-                       root.add 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
@@ -63,20 +90,22 @@ redef class MGroupPage
                concerns.sort_with(v.concerns_sorter)
                mentity.mproject.booster_rank = 0
                mentity.booster_rank = 0
-               root.add 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("concern:{mentity.nitdoc_id}", mentity)
                        if mentity isa MModule then
-                               root.add new DefinitionArticle(mentity)
-                       else
-                               root.add new ConcernSection(mentity)
+                               ssection.add_child new DefinitionArticle("article:{mentity.nitdoc_id}.definition", mentity)
                        end
+                       section.add_child ssection
                end
        end
 end
 
 redef class MModulePage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               var section = new MEntitySection("section:{mentity.nitdoc_name}", mentity)
+               root.add_child section
+               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
@@ -87,27 +116,30 @@ redef class MModulePage
                mentity.mgroup.mproject.booster_rank = 0
                mentity.mgroup.booster_rank = 0
                mentity.booster_rank = 0
-               root.add new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                # reference list
                for mentity in concerns do
-                       var section = 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 DefinitionArticle(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(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(new DefinitionArticle(mclassdef))
+                                               article.add_child(new DefinitionArticle(
+                                                       "article:{mclassdef.nitdoc_id}.definition", mclassdef))
                                        end
-                                       section.add article
+                                       ssection.add_child article
                                end
                        end
-                       root.add section
+                       section.add_child ssection
                end
        end
 
@@ -136,7 +168,9 @@ end
 
 redef class MClassPage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               var section = new MEntitySection("section:{mentity.nitdoc_name}", mentity)
+               root.add_child section
+               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
@@ -147,9 +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
-               root.add new ConcernsArticle(mentity, concerns)
+               var constructors = new ConstructorsSection(
+                       "article:{mentity.nitdoc_id}.constructors", mentity)
+               var minit = mentity.root_init
+               if minit != null then
+                       constructors.add_child new DefinitionArticle("article:{minit.nitdoc_id}.definition", minit)
+               end
+               section.add_child constructors
+               section.add_child new ConcernsArticle("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var section = 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)
@@ -157,12 +198,19 @@ redef class MClassPage
                                        v.name_sorter.sort(group)
                                        for mprop in group do
                                                for mpropdef in mpropdefs_for(mprop, mentity) do
-                                                       section.add new DefinitionArticle(mpropdef)
+                                                       if mpropdef isa MMethodDef and mpropdef.mproperty.is_init then
+                                                               if mpropdef == minit then continue
+                                                               constructors.add_child new DefinitionArticle(
+                                                                       "article:{mpropdef.nitdoc_id}.definition", mpropdef)
+                                                       else
+                                                               ssection.add_child new DefinitionArticle(
+                                                                       "article:{mpropdef.nitdoc_id}.definition", mpropdef)
+                                                       end
                                                end
                                        end
                                end
                        end
-                       root.add section
+                       section.add_child ssection
                end
        end
 
@@ -196,7 +244,9 @@ end
 
 redef class MPropertyPage
        redef fun apply_structure(v, doc) do
-               root.add new IntroArticle(mentity)
+               var section = new MEntitySection("section:{mentity.nitdoc_name}", mentity)
+               root.add_child section
+               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
@@ -207,18 +257,19 @@ 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
-               root.add new ConcernsArticle(mentity, concerns)
+               section.add_child new ConcernsArticle("article:{mentity.nitdoc_id}.concerns", mentity, concerns)
                for mentity in concerns do
-                       var section = 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
-                                       section.add new DefinitionArticle(mpropdef)
+                                       ssection.add_child new DefinitionArticle(
+                                               "article:{mpropdef.nitdoc_id}.definition", mpropdef)
                                end
                        end
-                       root.add section
+                       section.add_child ssection
                end
        end
 
@@ -234,6 +285,21 @@ redef class MPropertyPage
        end
 end
 
+# A group of sections that can be displayed together in a tab.
+#
+# Display the first child and hide less relevant data in other panels.
+class TabbedGroup
+       super DocSection
+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
@@ -242,6 +308,11 @@ class MEntityComposite
        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.
@@ -258,6 +329,14 @@ abstract class MEntityArticle
        super DocArticle
 end
 
+# A section about a Mentity.
+#
+# Used to regroup content about a MEntity.
+class MEntitySection
+       super MEntityComposite
+       super DocSection
+end
+
 # An introduction article about a MEntity.
 #
 # Used at the top of a documentation page to introduce the documented MEntity.
@@ -274,7 +353,37 @@ class ConcernsArticle
        var concerns: ConcernsTree
 end
 
+# An article that displaus a list of definition belonging to a MEntity.
+class DefinitionListArticle
+       super TabbedGroup
+       super MEntityArticle
+end
+
 # An article that display the definition text of a MEntity.
 class DefinitionArticle
        super MEntityArticle
 end
+
+# The main project article.
+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
+
+       # List of mmodules to display.
+       var mmodules: Array[MModule]
+
+       # List of mclasses to display.
+       var mclasses: Array[MClass]
+
+       # List of mproperties to display.
+       var mprops: Array[MProperty]
+end