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.
21 # StructurePhase populates the DocPage content with section and article.
23 # This phase only applies structure.
24 # The content of the structure is choosen by the rendering phases.
28 # Used to sort ConcernsTree by rank.
29 private var concerns_sorter
= new MConcernRankSorter
31 # Used to sort ConcernsTree by name.
32 private var name_sorter
= new MEntityNameSorter
34 # Populates the given DocModel.
36 for page
in doc
.pages
do page
.apply_structure
(self, doc
)
42 # Populates `self` with structure elements like DocComposite ones.
44 # See `StructurePhase`.
45 fun apply_structure
(v
: StructurePhase, doc
: DocModel) do end
48 redef class OverviewPage
49 redef fun apply_structure
(v
, doc
) do
50 var article
= new HomeArticle
51 root
.add_child article
53 var mprojects
= doc
.model
.mprojects
.to_a
54 var sorter
= new MConcernRankSorter
56 var section
= new ProjectsSection
57 for mproject
in mprojects
do
58 section
.add_child
new DefinitionArticle(mproject
)
60 article
.add_child section
64 redef class SearchPage
65 redef fun apply_structure
(v
, doc
) do
66 var mmodules
= doc
.mmodules
.to_a
67 v
.name_sorter
.sort
(mmodules
)
68 var mclasses
= doc
.mclasses
.to_a
69 v
.name_sorter
.sort
(mclasses
)
70 var mprops
= doc
.mproperties
.to_a
71 v
.name_sorter
.sort
(mprops
)
72 root
.add_child
new IndexArticle(mmodules
, mclasses
, mprops
)
76 redef class MGroupPage
77 redef fun apply_structure
(v
, doc
) do
78 var section
= new MEntitySection(mentity
)
79 root
.add_child section
80 if mentity
.is_root
then
81 section
.add_child
new IntroArticle(mentity
.mproject
)
83 section
.add_child
new IntroArticle(mentity
)
85 var concerns
= self.concerns
86 if concerns
== null or concerns
.is_empty
then return
88 mentity
.mproject
.booster_rank
= -1000
89 mentity
.booster_rank
= -1000
90 concerns
.sort_with
(v
.concerns_sorter
)
91 mentity
.mproject
.booster_rank
= 0
92 mentity
.booster_rank
= 0
93 section
.add_child
new ConcernsArticle(mentity
, concerns
)
94 for mentity
in concerns
do
95 var ssection
= new ConcernSection(mentity
)
96 if mentity
isa MModule then
97 ssection
.add_child
new DefinitionArticle(mentity
)
99 section
.add_child ssection
104 redef class MModulePage
105 redef fun apply_structure
(v
, doc
) do
106 var section
= new MEntitySection(mentity
)
107 root
.add_child section
108 section
.add_child
new IntroArticle(mentity
)
109 var concerns
= self.concerns
110 if concerns
== null or concerns
.is_empty
then return
112 mentity
.mgroup
.mproject
.booster_rank
= -1000
113 mentity
.mgroup
.booster_rank
= -1000
114 mentity
.booster_rank
= -1000
115 concerns
.sort_with
(v
.concerns_sorter
)
116 mentity
.mgroup
.mproject
.booster_rank
= 0
117 mentity
.mgroup
.booster_rank
= 0
118 mentity
.booster_rank
= 0
119 section
.add_child
new ConcernsArticle(mentity
, concerns
)
121 for mentity
in concerns
do
122 var ssection
= new ConcernSection(mentity
)
123 if mentity
isa MModule then
124 var mclasses
= mclasses_for_mmodule
(mentity
).to_a
125 v
.name_sorter
.sort
(mclasses
)
126 for mclass
in mclasses
do
127 var article
= new DefinitionListArticle(mclass
)
128 var mclassdefs
= mclassdefs_for
(mclass
).to_a
129 if not mclassdefs
.has
(mclass
.intro
) then
130 article
.add_child
(new DefinitionArticle(mclass
.intro
))
132 doc
.mainmodule
.linearize_mclassdefs
(mclassdefs
)
133 for mclassdef
in mclassdefs
do
134 article
.add_child
(new DefinitionArticle(mclassdef
))
136 ssection
.add_child article
139 section
.add_child ssection
143 # Filters `self.mclassses` by intro `mmodule`.
144 private fun mclasses_for_mmodule
(mmodule
: MModule): Set[MClass] do
145 var mclasses
= new HashSet[MClass]
146 for mclass
in self.mclasses
do
147 if mclass
.intro
.mmodule
== mmodule
then
154 # Filters `self.mclassdefs` by `mclass`.
155 private fun mclassdefs_for
(mclass
: MClass): Set[MClassDef] do
156 var mclassdefs
= new HashSet[MClassDef]
157 for mclassdef
in self.mclassdefs
do
158 if mclassdef
.mclass
== mclass
then
159 mclassdefs
.add mclassdef
166 redef class MClassPage
167 redef fun apply_structure
(v
, doc
) do
168 var section
= new MEntitySection(mentity
)
169 root
.add_child section
170 section
.add_child
new IntroArticle(mentity
)
171 var concerns
= self.concerns
172 if concerns
== null or concerns
.is_empty
then return
174 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= -1000
175 mentity
.intro_mmodule
.mgroup
.booster_rank
= -1000
176 mentity
.intro_mmodule
.booster_rank
= -1000
177 concerns
.sort_with
(v
.concerns_sorter
)
178 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= 0
179 mentity
.intro_mmodule
.mgroup
.booster_rank
= 0
180 mentity
.intro_mmodule
.booster_rank
= 0
181 var constructors
= new ConstructorsSection(mentity
)
182 var minit
= mentity
.root_init
183 if minit
!= null then
184 constructors
.add_child
new DefinitionArticle(minit
)
186 section
.add_child constructors
187 section
.add_child
new ConcernsArticle(mentity
, concerns
)
188 for mentity
in concerns
do
189 var ssection
= new ConcernSection(mentity
)
190 if mentity
isa MModule then
191 var mprops
= mproperties_for
(mentity
)
192 var by_kind
= new PropertiesByKind.with_elements
(mprops
)
193 for group
in by_kind
.groups
do
194 v
.name_sorter
.sort
(group
)
195 for mprop
in group
do
196 for mpropdef
in mpropdefs_for
(mprop
, mentity
) do
197 if mpropdef
isa MMethodDef and mpropdef
.mproperty
.is_init
then
198 if mpropdef
== minit
then continue
199 constructors
.add_child
new DefinitionArticle(mpropdef
)
201 ssection
.add_child
new DefinitionArticle(mpropdef
)
207 section
.add_child ssection
211 # Filters `self.mpropdefs` by `mmodule`.
214 private fun mproperties_for
(mmodule
: MModule): Set[MProperty] do
215 var mprops
= new HashSet[MProperty]
216 for mpropdef
in self.mpropdefs
do
217 if mpropdef
.mclassdef
.mmodule
== mmodule
then
218 mprops
.add mpropdef
.mproperty
224 # Filters `self.mpropdefs` by `mproperty`.
227 private fun mpropdefs_for
(mproperty
: MProperty, mmodule
: MModule): Set[MPropDef] do
228 var mpropdefs
= new HashSet[MPropDef]
229 for mpropdef
in self.mpropdefs
do
230 if mpropdef
.mproperty
== mproperty
and
231 mpropdef
.mclassdef
.mmodule
== mmodule
then
232 mpropdefs
.add mpropdef
239 redef class MPropertyPage
240 redef fun apply_structure
(v
, doc
) do
241 var section
= new MEntitySection(mentity
)
242 root
.add_child section
243 section
.add_child
new IntroArticle(mentity
)
244 var concerns
= self.concerns
245 if concerns
== null or concerns
.is_empty
then return
247 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= -1000
248 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= -1000
249 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= -1000
250 concerns
.sort_with
(v
.concerns_sorter
)
251 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= 0
252 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= 0
253 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= 0
254 section
.add_child
new ConcernsArticle(mentity
, concerns
)
255 for mentity
in concerns
do
256 var ssection
= new ConcernSection(mentity
)
257 if mentity
isa MModule then
259 var mpropdefs
= mpropdefs_for
(mentity
).to_a
260 v
.name_sorter
.sort
(mpropdefs
)
261 for mpropdef
in mpropdefs
do
262 ssection
.add_child
new DefinitionArticle(mpropdef
)
265 section
.add_child ssection
269 # Filters `self.mpropdefs` by `mmodule`.
270 private fun mpropdefs_for
(mmodule
: MModule): Set[MPropDef] do
271 var mpropdefs
= new HashSet[MPropDef]
272 for mpropdef
in self.mpropdefs
do
273 if mpropdef
.mclassdef
.mmodule
== mmodule
then
274 mpropdefs
.add mpropdef
281 # A group of sections that can be displayed together in a tab.
283 # Display the first child and hide less relevant data in other panels.
288 # A group of sections that can be displayed together in a tab panel.
292 # The title of this group.
293 var group_title
: String
296 # A DocComposite element about a MEntity.
297 class MEntityComposite
300 # MEntity documented by this page element.
304 # A list of constructors.
305 class ConstructorsSection
309 # A Section about a Concern.
311 # Those sections are used to build the page summary.
313 super MEntityComposite
317 # An article about a Mentity.
319 # Used to display textual content about a MEntity.
320 abstract class MEntityArticle
321 super MEntityComposite
325 # A section about a Mentity.
327 # Used to regroup content about a MEntity.
329 super MEntityComposite
333 # An introduction article about a MEntity.
335 # Used at the top of a documentation page to introduce the documented MEntity.
337 super MEntityComposite
341 # An article that display a ConcernsTreee as a list.
342 class ConcernsArticle
345 # Concerns to list in this article.
346 var concerns
: ConcernsTree
349 # An article that displaus a list of definition belonging to a MEntity.
350 class DefinitionListArticle
355 # An article that display the definition text of a MEntity.
356 class DefinitionArticle
360 # The main project article.
366 class ProjectsSection
370 # An article that display an index of mmodules, mclasses and mproperties.
374 # List of mmodules to display.
375 var mmodules
: Array[MModule]
377 # List of mclasses to display.
378 var mclasses
: Array[MClass]
380 # List of mproperties to display.
381 var mprops
: Array[MProperty]