30f98dbc7bc4dcea93caf7e9126c57c9a55ffa14
1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Generates lists about intros/redefs in MEntity.
17 # Actually, this works only for MModules and MclassDefs.
18 module doc_intros_redefs
22 # Computes intro / redef mentity list for each DefinitionArticle.
23 class IntroRedefListPhase
27 for page
in doc
.pages
.values
do
28 if not page
isa MEntityPage then continue
29 page
.root
.build_intro_redef_list
(self, doc
, page
)
34 redef class DocComposite
36 # Computes intro / redef lists for this page.
38 # See `IntroRedefListPhase`.
39 fun build_intro_redef_list
(v
: IntroRedefListPhase, doc
: DocModel, page
: MEntityPage) do
40 for child
in children
do child
.build_intro_redef_list
(v
, doc
, page
)
44 redef class DefinitionArticle
45 redef fun build_intro_redef_list
(v
, doc
, page
) do
46 var mentity
= self.mentity
47 if mentity
isa MModule then
48 build_mmodule_list
(v
, doc
, mentity
)
49 else if mentity
isa MClassDef and mentity
.mmodule
== page
.mentity
then
50 build_mclassdef_list
(v
, doc
, mentity
)
55 # TODO this should move to MEntity?
56 private fun build_mmodule_list
(v
: IntroRedefListPhase, doc
: DocModel, mmodule
: MModule) do
57 var section
= new IntrosRedefsSection("{mentity.nitdoc_id}.intros_redefs", mentity
)
58 var group
= new PanelGroup("list.group", "List")
59 var intros
= mmodule
.intro_mclassdefs
(v
.ctx
.min_visibility
).to_a
60 doc
.mainmodule
.linearize_mclassdefs
(intros
)
61 group
.add_child
new IntrosRedefsListArticle("{mentity.nitdoc_id}.intros", "Introduces", intros
)
62 var redefs
= mmodule
.redef_mclassdefs
(v
.ctx
.min_visibility
).to_a
63 doc
.mainmodule
.linearize_mclassdefs
(redefs
)
64 group
.add_child
new IntrosRedefsListArticle("{mentity.nitdoc_id}.redefs", "Redefines", redefs
)
65 section
.add_child group
69 # TODO this should move to MEntity?
70 private fun build_mclassdef_list
(v
: IntroRedefListPhase, doc
: DocModel, mclassdef
: MClassDef) do
71 var section
= new IntrosRedefsSection("{mentity.nitdoc_id}.intros_redefs", mentity
)
72 var group
= new PanelGroup("list.group", "List")
73 var intros
= mclassdef
.collect_intro_mpropdefs
(v
.ctx
.min_visibility
).to_a
74 # FIXME avoid diff changes
75 # v.ctx.mainmodule.linearize_mpropdefs(intros)
76 group
.add_child
new IntrosRedefsListArticle("{mentity.nitdoc_id}.intros", "Introduces", intros
)
77 var redefs
= mclassdef
.collect_redef_mpropdefs
(v
.ctx
.min_visibility
).to_a
78 # FIXME avoid diff changes
79 # v.ctx.mainmodule.linearize_mpropdefs(redefs)
80 group
.add_child
new IntrosRedefsListArticle("{mentity.nitdoc_id}.redefs", "Redefines", redefs
)
81 section
.add_child group
87 # Section that contains the intros and redefs lists.
88 class IntrosRedefsSection
92 redef var is_toc_hidden
= true
95 # An article that displays a list of introduced / refined mentities.
98 # This can merged with InheritanceListArticle in a more generic class.
99 class IntrosRedefsListArticle
102 # Intro mentities to list.
103 var mentities
: Array[MEntity]
105 redef fun is_hidden
do return mentities
.is_empty
106 redef var is_toc_hidden
= true