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 page
.apply_structure
(self, doc
)
41 # Populates `self` with structure elements like DocComposite ones.
43 # See `StructurePhase`.
44 fun apply_structure
(v
: StructurePhase, doc
: DocModel) do end
47 redef class OverviewPage
48 redef fun apply_structure
(v
, doc
) do
49 var article
= new HomeArticle
50 root
.add_child article
52 var mprojects
= doc
.model
.mprojects
.to_a
53 var sorter
= new MConcernRankSorter
55 var section
= new ProjectsSection
56 for mproject
in mprojects
do
57 section
.add_child
new DefinitionArticle(mproject
)
59 article
.add_child section
63 redef class SearchPage
64 redef fun apply_structure
(v
, doc
) do
65 var mmodules
= doc
.mmodules
.to_a
66 v
.name_sorter
.sort
(mmodules
)
67 var mclasses
= doc
.mclasses
.to_a
68 v
.name_sorter
.sort
(mclasses
)
69 var mprops
= doc
.mproperties
.to_a
70 v
.name_sorter
.sort
(mprops
)
71 root
.add_child
new IndexArticle(mmodules
, mclasses
, mprops
)
75 redef class MGroupPage
76 redef fun apply_structure
(v
, doc
) do
77 var section
= new MEntitySection(mentity
)
78 root
.add_child section
79 if mentity
.is_root
then
80 section
.add_child
new IntroArticle(mentity
.mproject
)
82 section
.add_child
new IntroArticle(mentity
)
84 var concerns
= self.concerns
85 if concerns
== null or concerns
.is_empty
then return
87 mentity
.mproject
.booster_rank
= -1000
88 mentity
.booster_rank
= -1000
89 concerns
.sort_with
(v
.concerns_sorter
)
90 mentity
.mproject
.booster_rank
= 0
91 mentity
.booster_rank
= 0
92 section
.add_child
new ConcernsArticle(mentity
, concerns
)
93 for mentity
in concerns
do
94 var ssection
= new ConcernSection(mentity
)
95 if mentity
isa MModule then
96 ssection
.add_child
new DefinitionArticle(mentity
)
98 section
.add_child ssection
103 redef class MModulePage
104 redef fun apply_structure
(v
, doc
) do
105 var section
= new MEntitySection(mentity
)
106 root
.add_child section
107 section
.add_child
new IntroArticle(mentity
)
108 var concerns
= self.concerns
109 if concerns
== null or concerns
.is_empty
then return
111 mentity
.mgroup
.mproject
.booster_rank
= -1000
112 mentity
.mgroup
.booster_rank
= -1000
113 mentity
.booster_rank
= -1000
114 concerns
.sort_with
(v
.concerns_sorter
)
115 mentity
.mgroup
.mproject
.booster_rank
= 0
116 mentity
.mgroup
.booster_rank
= 0
117 mentity
.booster_rank
= 0
118 section
.add_child
new ConcernsArticle(mentity
, concerns
)
120 for mentity
in concerns
do
121 var ssection
= new ConcernSection(mentity
)
122 if mentity
isa MModule then
123 var mclasses
= mclasses_for_mmodule
(mentity
).to_a
124 v
.name_sorter
.sort
(mclasses
)
125 for mclass
in mclasses
do
126 var article
= new DefinitionArticle(mclass
)
127 var mclassdefs
= mclassdefs_for
(mclass
).to_a
128 if not mclassdefs
.has
(mclass
.intro
) then
129 article
.add_child
(new DefinitionArticle(mclass
.intro
))
131 doc
.mainmodule
.linearize_mclassdefs
(mclassdefs
)
132 for mclassdef
in mclassdefs
do
133 article
.add_child
(new DefinitionArticle(mclassdef
))
135 ssection
.add_child article
138 section
.add_child ssection
142 # Filters `self.mclassses` by intro `mmodule`.
143 private fun mclasses_for_mmodule
(mmodule
: MModule): Set[MClass] do
144 var mclasses
= new HashSet[MClass]
145 for mclass
in self.mclasses
do
146 if mclass
.intro
.mmodule
== mmodule
then
153 # Filters `self.mclassdefs` by `mclass`.
154 private fun mclassdefs_for
(mclass
: MClass): Set[MClassDef] do
155 var mclassdefs
= new HashSet[MClassDef]
156 for mclassdef
in self.mclassdefs
do
157 if mclassdef
.mclass
== mclass
then
158 mclassdefs
.add mclassdef
165 redef class MClassPage
166 redef fun apply_structure
(v
, doc
) do
167 var section
= new MEntitySection(mentity
)
168 root
.add_child section
169 section
.add_child
new IntroArticle(mentity
)
170 var concerns
= self.concerns
171 if concerns
== null or concerns
.is_empty
then return
173 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= -1000
174 mentity
.intro_mmodule
.mgroup
.booster_rank
= -1000
175 mentity
.intro_mmodule
.booster_rank
= -1000
176 concerns
.sort_with
(v
.concerns_sorter
)
177 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= 0
178 mentity
.intro_mmodule
.mgroup
.booster_rank
= 0
179 mentity
.intro_mmodule
.booster_rank
= 0
180 section
.add_child
new ConcernsArticle(mentity
, concerns
)
181 for mentity
in concerns
do
182 var ssection
= new ConcernSection(mentity
)
183 if mentity
isa MModule then
184 var mprops
= mproperties_for
(mentity
)
185 var by_kind
= new PropertiesByKind.with_elements
(mprops
)
186 for group
in by_kind
.groups
do
187 v
.name_sorter
.sort
(group
)
188 for mprop
in group
do
189 for mpropdef
in mpropdefs_for
(mprop
, mentity
) do
190 ssection
.add_child
new DefinitionArticle(mpropdef
)
195 section
.add_child ssection
199 # Filters `self.mpropdefs` by `mmodule`.
202 private fun mproperties_for
(mmodule
: MModule): Set[MProperty] do
203 var mprops
= new HashSet[MProperty]
204 for mpropdef
in self.mpropdefs
do
205 if mpropdef
.mclassdef
.mmodule
== mmodule
then
206 mprops
.add mpropdef
.mproperty
212 # Filters `self.mpropdefs` by `mproperty`.
215 private fun mpropdefs_for
(mproperty
: MProperty, mmodule
: MModule): Set[MPropDef] do
216 var mpropdefs
= new HashSet[MPropDef]
217 for mpropdef
in self.mpropdefs
do
218 if mpropdef
.mproperty
== mproperty
and
219 mpropdef
.mclassdef
.mmodule
== mmodule
then
220 mpropdefs
.add mpropdef
227 redef class MPropertyPage
228 redef fun apply_structure
(v
, doc
) do
229 var section
= new MEntitySection(mentity
)
230 root
.add_child section
231 section
.add_child
new IntroArticle(mentity
)
232 var concerns
= self.concerns
233 if concerns
== null or concerns
.is_empty
then return
235 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= -1000
236 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= -1000
237 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= -1000
238 concerns
.sort_with
(v
.concerns_sorter
)
239 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= 0
240 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= 0
241 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= 0
242 section
.add_child
new ConcernsArticle(mentity
, concerns
)
243 for mentity
in concerns
do
244 var ssection
= new ConcernSection(mentity
)
245 if mentity
isa MModule then
247 var mpropdefs
= mpropdefs_for
(mentity
).to_a
248 v
.name_sorter
.sort
(mpropdefs
)
249 for mpropdef
in mpropdefs
do
250 ssection
.add_child
new DefinitionArticle(mpropdef
)
253 section
.add_child ssection
257 # Filters `self.mpropdefs` by `mmodule`.
258 private fun mpropdefs_for
(mmodule
: MModule): Set[MPropDef] do
259 var mpropdefs
= new HashSet[MPropDef]
260 for mpropdef
in self.mpropdefs
do
261 if mpropdef
.mclassdef
.mmodule
== mmodule
then
262 mpropdefs
.add mpropdef
269 # A DocComposite element about a MEntity.
270 class MEntityComposite
273 # MEntity documented by this page element.
277 # A Section about a Concern.
279 # Those sections are used to build the page summary.
281 super MEntityComposite
285 # An article about a Mentity.
287 # Used to display textual content about a MEntity.
288 abstract class MEntityArticle
289 super MEntityComposite
293 # A section about a Mentity.
295 # Used to regroup content about a MEntity.
297 super MEntityComposite
301 # An introduction article about a MEntity.
303 # Used at the top of a documentation page to introduce the documented MEntity.
305 super MEntityComposite
309 # An article that display a ConcernsTreee as a list.
310 class ConcernsArticle
313 # Concerns to list in this article.
314 var concerns
: ConcernsTree
317 # An article that display the definition text of a MEntity.
318 class DefinitionArticle
322 # The main project article.
328 class ProjectsSection
332 # An article that display an index of mmodules, mclasses and mproperties.
336 # List of mmodules to display.
337 var mmodules
: Array[MModule]
339 # List of mclasses to display.
340 var mclasses
: Array[MClass]
342 # List of mproperties to display.
343 var mprops
: Array[MProperty]