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 # Composes the DocComposite tree of a DocPage and organizes its content.
20 # StructurePhase populates the DocPage content with section and article.
22 # This phase only applies structure.
23 # The content of the structure is choosen by the rendering phases.
27 # Used to sort ConcernsTree by rank.
28 private var concerns_sorter
= new MConcernRankSorter
30 # Used to sort ConcernsTree by name.
31 private var name_sorter
= new MEntityNameSorter
33 # Populates the given DocModel.
35 for page
in doc
.pages
do
36 if page
isa MEntityPage then page
.apply_structure
(self, doc
)
40 # TODO index and search page should also be structured here
43 redef class MEntityPage
45 # Populates `self` with structure elements like DocComposite ones.
47 # See `StructurePhase`.
48 fun apply_structure
(v
: StructurePhase, doc
: DocModel) do end
51 redef class MGroupPage
52 redef fun apply_structure
(v
, doc
) do
53 if mentity
.is_root
then
54 root
.add_child
new IntroArticle(mentity
.mproject
)
56 root
.add_child
new IntroArticle(mentity
)
58 var concerns
= self.concerns
59 if concerns
== null or concerns
.is_empty
then return
61 mentity
.mproject
.booster_rank
= -1000
62 mentity
.booster_rank
= -1000
63 concerns
.sort_with
(v
.concerns_sorter
)
64 mentity
.mproject
.booster_rank
= 0
65 mentity
.booster_rank
= 0
66 root
.add_child
new ConcernsArticle(mentity
, concerns
)
67 for mentity
in concerns
do
68 if mentity
isa MModule then
69 root
.add_child
new DefinitionArticle(mentity
)
71 root
.add_child
new ConcernSection(mentity
)
77 redef class MModulePage
78 redef fun apply_structure
(v
, doc
) do
79 root
.add_child
new IntroArticle(mentity
)
80 var concerns
= self.concerns
81 if concerns
== null or concerns
.is_empty
then return
83 mentity
.mgroup
.mproject
.booster_rank
= -1000
84 mentity
.mgroup
.booster_rank
= -1000
85 mentity
.booster_rank
= -1000
86 concerns
.sort_with
(v
.concerns_sorter
)
87 mentity
.mgroup
.mproject
.booster_rank
= 0
88 mentity
.mgroup
.booster_rank
= 0
89 mentity
.booster_rank
= 0
90 root
.add_child
new ConcernsArticle(mentity
, concerns
)
92 for mentity
in concerns
do
93 var section
= new ConcernSection(mentity
)
94 if mentity
isa MModule then
95 var mclasses
= mclasses_for_mmodule
(mentity
).to_a
96 v
.name_sorter
.sort
(mclasses
)
97 for mclass
in mclasses
do
98 var article
= new DefinitionArticle(mclass
)
99 var mclassdefs
= mclassdefs_for
(mclass
).to_a
100 if not mclassdefs
.has
(mclass
.intro
) then
101 article
.add_child
(new DefinitionArticle(mclass
.intro
))
103 doc
.mainmodule
.linearize_mclassdefs
(mclassdefs
)
104 for mclassdef
in mclassdefs
do
105 article
.add_child
(new DefinitionArticle(mclassdef
))
107 section
.add_child article
110 root
.add_child section
114 # Filters `self.mclassses` by intro `mmodule`.
115 private fun mclasses_for_mmodule
(mmodule
: MModule): Set[MClass] do
116 var mclasses
= new HashSet[MClass]
117 for mclass
in self.mclasses
do
118 if mclass
.intro
.mmodule
== mmodule
then
125 # Filters `self.mclassdefs` by `mclass`.
126 private fun mclassdefs_for
(mclass
: MClass): Set[MClassDef] do
127 var mclassdefs
= new HashSet[MClassDef]
128 for mclassdef
in self.mclassdefs
do
129 if mclassdef
.mclass
== mclass
then
130 mclassdefs
.add mclassdef
137 redef class MClassPage
138 redef fun apply_structure
(v
, doc
) do
139 root
.add_child
new IntroArticle(mentity
)
140 var concerns
= self.concerns
141 if concerns
== null or concerns
.is_empty
then return
143 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= -1000
144 mentity
.intro_mmodule
.mgroup
.booster_rank
= -1000
145 mentity
.intro_mmodule
.booster_rank
= -1000
146 concerns
.sort_with
(v
.concerns_sorter
)
147 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= 0
148 mentity
.intro_mmodule
.mgroup
.booster_rank
= 0
149 mentity
.intro_mmodule
.booster_rank
= 0
150 root
.add_child
new ConcernsArticle(mentity
, concerns
)
151 for mentity
in concerns
do
152 var section
= new ConcernSection(mentity
)
153 if mentity
isa MModule then
154 var mprops
= mproperties_for
(mentity
)
155 var by_kind
= new PropertiesByKind.with_elements
(mprops
)
156 for group
in by_kind
.groups
do
157 v
.name_sorter
.sort
(group
)
158 for mprop
in group
do
159 for mpropdef
in mpropdefs_for
(mprop
, mentity
) do
160 section
.add_child
new DefinitionArticle(mpropdef
)
165 root
.add_child section
169 # Filters `self.mpropdefs` by `mmodule`.
172 private fun mproperties_for
(mmodule
: MModule): Set[MProperty] do
173 var mprops
= new HashSet[MProperty]
174 for mpropdef
in self.mpropdefs
do
175 if mpropdef
.mclassdef
.mmodule
== mmodule
then
176 mprops
.add mpropdef
.mproperty
182 # Filters `self.mpropdefs` by `mproperty`.
185 private fun mpropdefs_for
(mproperty
: MProperty, mmodule
: MModule): Set[MPropDef] do
186 var mpropdefs
= new HashSet[MPropDef]
187 for mpropdef
in self.mpropdefs
do
188 if mpropdef
.mproperty
== mproperty
and
189 mpropdef
.mclassdef
.mmodule
== mmodule
then
190 mpropdefs
.add mpropdef
197 redef class MPropertyPage
198 redef fun apply_structure
(v
, doc
) do
199 root
.add_child
new IntroArticle(mentity
)
200 var concerns
= self.concerns
201 if concerns
== null or concerns
.is_empty
then return
203 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= -1000
204 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= -1000
205 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= -1000
206 concerns
.sort_with
(v
.concerns_sorter
)
207 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= 0
208 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= 0
209 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= 0
210 root
.add_child
new ConcernsArticle(mentity
, concerns
)
211 for mentity
in concerns
do
212 var section
= new ConcernSection(mentity
)
213 if mentity
isa MModule then
215 var mpropdefs
= mpropdefs_for
(mentity
).to_a
216 v
.name_sorter
.sort
(mpropdefs
)
217 for mpropdef
in mpropdefs
do
218 section
.add_child
new DefinitionArticle(mpropdef
)
221 root
.add_child section
225 # Filters `self.mpropdefs` by `mmodule`.
226 private fun mpropdefs_for
(mmodule
: MModule): Set[MPropDef] do
227 var mpropdefs
= new HashSet[MPropDef]
228 for mpropdef
in self.mpropdefs
do
229 if mpropdef
.mclassdef
.mmodule
== mmodule
then
230 mpropdefs
.add mpropdef
237 # A DocComposite element about a MEntity.
238 class MEntityComposite
241 # MEntity documented by this page element.
245 # A Section about a Concern.
247 # Those sections are used to build the page summary.
249 super MEntityComposite
253 # An article about a Mentity.
255 # Used to display textual content about a MEntity.
256 abstract class MEntityArticle
257 super MEntityComposite
261 # An introduction article about a MEntity.
263 # Used at the top of a documentation page to introduce the documented MEntity.
265 super MEntityComposite
269 # An article that display a ConcernsTreee as a list.
270 class ConcernsArticle
273 # Concerns to list in this article.
274 var concerns
: ConcernsTree
277 # An article that display the definition text of a MEntity.
278 class DefinitionArticle