a543c4658dd4d6d16e9a61dd62da2e2ab0343ab1
[nit.git] / src / doc / doc_phases / doc_hierarchies.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Computes importation and class hierarchy lists.
16 module doc_hierarchies
17
18 import doc_structure
19 import doc_poset
20
21 # Insert inheritance / importation lists in the page.
22 class InheritanceListsPhase
23 super DocPhase
24
25 # Used to sort list by name.
26 var name_sorter = new MEntityNameSorter
27
28 redef fun apply do
29 for page in doc.pages.values do
30 if page isa MEntityPage then page.build_inh_list(self, doc)
31 end
32 end
33 end
34
35 redef class MEntityPage
36
37 # Build importation / inheritance list for this page.
38 fun build_inh_list(v: InheritanceListsPhase, doc: DocModel) do end
39 end
40
41 redef class MModulePage
42 redef fun build_inh_list(v, doc) do
43 var id = mentity.nitdoc_id
44 var section = new ImportationListSection("{id}.importation", mentity)
45 var group = new PanelGroup("list.group", "List")
46 var imports = self.imports.to_a
47 v.name_sorter.sort(imports)
48 group.add_child new HierarchyListArticle("{id}.imports", "Imports", imports)
49 var clients = self.clients.to_a
50 v.name_sorter.sort(clients)
51 group.add_child new HierarchyListArticle("{id}.clients", "Clients", clients)
52 section.add_child group
53 section.parent = root.children.first
54 root.children.first.children.insert(section, 1)
55 end
56 end
57
58 redef class MClassPage
59 redef fun build_inh_list(v, doc) do
60 var id = mentity.nitdoc_id
61 var section = new InheritanceListSection("{id}.inheritance", mentity)
62 var group = new PanelGroup("list.group", "List")
63 var parents = self.parents.to_a
64 v.name_sorter.sort(parents)
65 group.add_child new HierarchyListArticle("{id}.parents", "Parents", parents)
66 var ancestors = self.ancestors.to_a
67 v.name_sorter.sort(ancestors)
68 group.add_child new HierarchyListArticle("{id}.ancestors", "Ancestors", ancestors)
69 var children = self.children.to_a
70 v.name_sorter.sort(children)
71 group.add_child new HierarchyListArticle("{id}.children", "Children", children)
72 var descendants = self.descendants.to_a
73 v.name_sorter.sort(descendants)
74 group.add_child new HierarchyListArticle("{id}.descendants", "Descendants", descendants)
75 section.add_child group
76 section.parent = root.children.first
77 root.children.first.children.insert(section, 1)
78 end
79 end
80
81 # FIXME diff hack
82 class ImportationListSection
83 super TabbedGroup
84 super MEntityComposite
85 end
86
87 # FIXME diff hack
88 class InheritanceListSection
89 super TabbedGroup
90 super MEntityComposite
91 end
92
93 # Dislay a hierarchical list of mentities.
94 class HierarchyListArticle
95 super DocArticle
96
97 # MEntities to display in this list.
98 var mentities: Array[MEntity]
99
100 redef fun is_hidden do return mentities.is_empty
101 end