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
.values
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("home.article")
51 root
.add_child article
53 var mprojects
= doc
.model
.mprojects
.to_a
54 var sorter
= new MConcernRankSorter
56 var section
= new ProjectsSection("projects.section")
57 for mproject
in mprojects
do
58 section
.add_child
new DefinitionArticle("{mproject.nitdoc_id}.definition", 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("index.article", mmodules
, mclasses
, mprops
)
76 redef class MGroupPage
77 redef fun apply_structure
(v
, doc
) do
78 var section
= new MEntitySection("{mentity.nitdoc_name}.section", mentity
)
79 root
.add_child section
80 if mentity
.is_root
then
81 section
.add_child
new IntroArticle("{mentity.mproject.nitdoc_id}.intro", mentity
.mproject
)
83 section
.add_child
new IntroArticle("{mentity.nitdoc_id}.intro", 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.nitdoc_id}.concerns", mentity
, concerns
)
94 for mentity
in concerns
do
95 var ssection
= new ConcernSection("concern:{mentity.nitdoc_id}", mentity
)
96 if mentity
isa MModule then
97 ssection
.add_child
new DefinitionArticle("{mentity.nitdoc_id}.definition", mentity
)
99 section
.add_child ssection
104 redef class MModulePage
105 redef fun apply_structure
(v
, doc
) do
106 var section
= new MEntitySection("{mentity.nitdoc_name}.section", mentity
)
107 root
.add_child section
108 section
.add_child
new IntroArticle("{mentity.nitdoc_id}.intro", 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.nitdoc_id}.concerns", mentity
, concerns
)
121 for mentity
in concerns
do
122 var ssection
= new ConcernSection("concern:{mentity.nitdoc_id}", 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(
128 "{mclass.intro.nitdoc_id}.definition-list", mclass
)
129 var mclassdefs
= mclassdefs_for
(mclass
).to_a
130 if not mclassdefs
.has
(mclass
.intro
) then
131 article
.add_child
(new DefinitionArticle(
132 "{mclass.intro.nitdoc_id}.definition", mclass
.intro
))
134 doc
.mainmodule
.linearize_mclassdefs
(mclassdefs
)
135 for mclassdef
in mclassdefs
do
136 article
.add_child
(new DefinitionArticle(
137 "{mclassdef.nitdoc_id}.definition", mclassdef
))
139 ssection
.add_child article
142 section
.add_child ssection
146 # Filters `self.mclassses` by intro `mmodule`.
147 private fun mclasses_for_mmodule
(mmodule
: MModule): Set[MClass] do
148 var mclasses
= new HashSet[MClass]
149 for mclass
in self.mclasses
do
150 if mclass
.intro
.mmodule
== mmodule
then
157 # Filters `self.mclassdefs` by `mclass`.
158 private fun mclassdefs_for
(mclass
: MClass): Set[MClassDef] do
159 var mclassdefs
= new HashSet[MClassDef]
160 for mclassdef
in self.mclassdefs
do
161 if mclassdef
.mclass
== mclass
then
162 mclassdefs
.add mclassdef
169 redef class MClassPage
170 redef fun apply_structure
(v
, doc
) do
171 var section
= new MEntitySection("{mentity.nitdoc_name}.section", mentity
)
172 root
.add_child section
173 section
.add_child
new IntroArticle("{mentity.nitdoc_id}.intro", mentity
)
174 var concerns
= self.concerns
175 if concerns
== null or concerns
.is_empty
then return
177 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= -1000
178 mentity
.intro_mmodule
.mgroup
.booster_rank
= -1000
179 mentity
.intro_mmodule
.booster_rank
= -1000
180 concerns
.sort_with
(v
.concerns_sorter
)
181 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= 0
182 mentity
.intro_mmodule
.mgroup
.booster_rank
= 0
183 mentity
.intro_mmodule
.booster_rank
= 0
184 var constructors
= new ConstructorsSection(
185 "{mentity.nitdoc_id}.constructors", mentity
)
186 var minit
= mentity
.root_init
187 if minit
!= null then
188 constructors
.add_child
new DefinitionArticle("{minit.nitdoc_id}.definition", minit
)
190 section
.add_child constructors
191 section
.add_child
new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity
, concerns
)
192 for mentity
in concerns
do
193 var ssection
= new ConcernSection("concern:{mentity.nitdoc_id}", mentity
)
194 if mentity
isa MModule then
195 var mprops
= mproperties_for
(mentity
)
196 var by_kind
= new PropertiesByKind.with_elements
(mprops
)
197 for group
in by_kind
.groups
do
198 v
.name_sorter
.sort
(group
)
199 for mprop
in group
do
200 for mpropdef
in mpropdefs_for
(mprop
, mentity
) do
201 if mpropdef
isa MMethodDef and mpropdef
.mproperty
.is_init
then
202 if mpropdef
== minit
then continue
203 constructors
.add_child
new DefinitionArticle(
204 "{mpropdef.nitdoc_id}.definition", mpropdef
)
206 ssection
.add_child
new DefinitionArticle(
207 "{mpropdef.nitdoc_id}.definition", mpropdef
)
213 section
.add_child ssection
217 # Filters `self.mpropdefs` by `mmodule`.
220 private fun mproperties_for
(mmodule
: MModule): Set[MProperty] do
221 var mprops
= new HashSet[MProperty]
222 for mpropdef
in self.mpropdefs
do
223 if mpropdef
.mclassdef
.mmodule
== mmodule
then
224 mprops
.add mpropdef
.mproperty
230 # Filters `self.mpropdefs` by `mproperty`.
233 private fun mpropdefs_for
(mproperty
: MProperty, mmodule
: MModule): Set[MPropDef] do
234 var mpropdefs
= new HashSet[MPropDef]
235 for mpropdef
in self.mpropdefs
do
236 if mpropdef
.mproperty
== mproperty
and
237 mpropdef
.mclassdef
.mmodule
== mmodule
then
238 mpropdefs
.add mpropdef
245 redef class MPropertyPage
246 redef fun apply_structure
(v
, doc
) do
247 var section
= new MEntitySection("{mentity.nitdoc_name}.section", mentity
)
248 root
.add_child section
249 section
.add_child
new IntroArticle("{mentity.nitdoc_id}.intro", mentity
)
250 var concerns
= self.concerns
251 if concerns
== null or concerns
.is_empty
then return
253 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= -1000
254 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= -1000
255 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= -1000
256 concerns
.sort_with
(v
.concerns_sorter
)
257 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= 0
258 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= 0
259 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= 0
260 section
.add_child
new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity
, concerns
)
261 for mentity
in concerns
do
262 var ssection
= new ConcernSection("concern:{mentity.nitdoc_id}", mentity
)
263 if mentity
isa MModule then
265 var mpropdefs
= mpropdefs_for
(mentity
).to_a
266 v
.name_sorter
.sort
(mpropdefs
)
267 for mpropdef
in mpropdefs
do
268 ssection
.add_child
new DefinitionArticle(
269 "{mpropdef.nitdoc_id}.definition", mpropdef
)
272 section
.add_child ssection
276 # Filters `self.mpropdefs` by `mmodule`.
277 private fun mpropdefs_for
(mmodule
: MModule): Set[MPropDef] do
278 var mpropdefs
= new HashSet[MPropDef]
279 for mpropdef
in self.mpropdefs
do
280 if mpropdef
.mclassdef
.mmodule
== mmodule
then
281 mpropdefs
.add mpropdef
288 # A group of sections that can be displayed together in a tab.
290 # Display the first child and hide less relevant data in other panels.
295 # A group of sections that can be displayed together in a tab panel.
299 # The title of this group.
300 var group_title
: String
303 # A DocComposite element about a MEntity.
304 class MEntityComposite
307 # MEntity documented by this page element.
311 # A list of constructors.
312 class ConstructorsSection
316 # A Section about a Concern.
318 # Those sections are used to build the page summary.
320 super MEntityComposite
324 # An article about a Mentity.
326 # Used to display textual content about a MEntity.
327 abstract class MEntityArticle
328 super MEntityComposite
332 # A section about a Mentity.
334 # Used to regroup content about a MEntity.
336 super MEntityComposite
340 # An introduction article about a MEntity.
342 # Used at the top of a documentation page to introduce the documented MEntity.
344 super MEntityComposite
348 # An article that display a ConcernsTreee as a list.
349 class ConcernsArticle
352 # Concerns to list in this article.
353 var concerns
: ConcernsTree
356 # An article that displaus a list of definition belonging to a MEntity.
357 class DefinitionListArticle
362 # An article that display the definition text of a MEntity.
363 class DefinitionArticle
367 # The main project article.
373 class ProjectsSection
377 # An article that display an index of mmodules, mclasses and mproperties.
381 # List of mmodules to display.
382 var mmodules
: Array[MModule]
384 # List of mclasses to display.
385 var mclasses
: Array[MClass]
387 # List of mproperties to display.
388 var mprops
: Array[MProperty]
393 # Sort MConcerns based on the module importation hierarchy ranking
394 # see also: `MConcern::concern_rank` and `MConcern::booster_rank`
396 # Comparison is made with the formula:
399 # a.concern_rank + a.booster_rank <=> b.concern_rank + b.booster_ran
402 # If both `a` and `b` have the same ranking,
403 # ordering is based on lexicographic comparison of `a.name` and `b.name`
404 class MConcernRankSorter
406 redef type COMPARED: MConcern
408 redef fun compare
(a
, b
) do
409 if a
.concern_rank
== b
.concern_rank
then
410 return a
.name
<=> b
.name
412 return a
.concern_rank
+ a
.booster_rank
<=> b
.concern_rank
+ b
.booster_rank
418 # Boost a MConcern rank
419 # see: `MConcernRankSorter`
420 # Use a positive booster to push down a result in the list
421 # A negative booster can be used to push up the result
422 var booster_rank
: Int = 0 is writable
424 # Concern ranking used for ordering
425 # see: `MConcernRankSorter`
426 # Rank can be positive or negative
427 fun concern_rank
: Int is abstract
431 redef var concern_rank
is lazy
do
433 for mgroup
in mgroups
do
434 var mmax
= mgroup
.concern_rank
435 if mmax
> max
then max
= mmax
442 redef var concern_rank
is lazy
do
444 for mmodule
in mmodules
do
445 var mmax
= mmodule
.concern_rank
446 if mmax
> max
then max
= mmax
453 redef var concern_rank
is lazy
do
455 for p
in in_importation
.direct_greaters
do
456 var pmax
= p
.concern_rank
457 if pmax
> max
then max
= pmax