Merge: Nitg-g new NativeArray fix
[nit.git] / src / doc / doc_phases / doc_structure.nit
index 384f603..7491e4b 100644 (file)
@@ -16,6 +16,7 @@
 module doc_structure
 
 import doc_concerns
+import modelize
 
 # StructurePhase populates the DocPage content with section and article.
 #
@@ -32,10 +33,8 @@ class StructurePhase
 
        # Populates the given DocModel.
        redef fun apply do
-               for page in doc.pages do page.apply_structure(self, doc)
+               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 DocPage
@@ -62,6 +61,18 @@ redef class OverviewPage
        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(mmodules, mclasses, mprops)
+       end
+end
+
 redef class MGroupPage
        redef fun apply_structure(v, doc) do
                var section = new MEntitySection(mentity)
@@ -81,11 +92,11 @@ redef class MGroupPage
                mentity.booster_rank = 0
                section.add_child new ConcernsArticle(mentity, concerns)
                for mentity in concerns do
+                       var ssection = new ConcernSection(mentity)
                        if mentity isa MModule then
-                               section.add_child new DefinitionArticle(mentity)
-                       else
-                               section.add_child new ConcernSection(mentity)
+                               ssection.add_child new DefinitionArticle(mentity)
                        end
+                       section.add_child ssection
                end
        end
 end
@@ -113,7 +124,7 @@ redef class MModulePage
                                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(mclass)
                                        var mclassdefs = mclassdefs_for(mclass).to_a
                                        if not mclassdefs.has(mclass.intro) then
                                                article.add_child(new DefinitionArticle(mclass.intro))
@@ -167,6 +178,12 @@ 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 minit = mentity.root_init
+               if minit != null then
+                       constructors.add_child new DefinitionArticle(minit)
+               end
+               section.add_child constructors
                section.add_child new ConcernsArticle(mentity, concerns)
                for mentity in concerns do
                        var ssection = new ConcernSection(mentity)
@@ -177,7 +194,12 @@ redef class MClassPage
                                        v.name_sorter.sort(group)
                                        for mprop in group do
                                                for mpropdef in mpropdefs_for(mprop, mentity) do
-                                                       ssection.add_child new DefinitionArticle(mpropdef)
+                                                       if mpropdef isa MMethodDef and mpropdef.mproperty.is_init then
+                                                               if mpropdef == minit then continue
+                                                               constructors.add_child new DefinitionArticle(mpropdef)
+                                                       else
+                                                               ssection.add_child new DefinitionArticle(mpropdef)
+                                                       end
                                                end
                                        end
                                end
@@ -256,6 +278,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
@@ -264,6 +301,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.
@@ -304,6 +346,12 @@ 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
@@ -318,3 +366,17 @@ end
 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