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", "Home")
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", "Projects")
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("{mentity.nitdoc_id}.concern", 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("{mentity.nitdoc_id}.concern", 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("{mentity.nitdoc_id}.concern", 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("{mentity.nitdoc_id}.concern", 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.
300 # A DocComposite element about a MEntity.
301 class MEntityComposite
304 redef fun title
do return mentity
.nitdoc_name
306 # MEntity documented by this page element.
310 # A list of constructors.
311 class ConstructorsSection
315 # A Section about a Concern.
317 # Those sections are used to build the page summary.
319 super MEntityComposite
322 redef fun is_toc_hidden
do return is_hidden
325 # An article about a Mentity.
327 # Used to display textual content about a MEntity.
328 abstract class MEntityArticle
329 super MEntityComposite
333 # A section about a Mentity.
335 # Used to regroup content about a MEntity.
337 super MEntityComposite
341 # An introduction article about a MEntity.
343 # Used at the top of a documentation page to introduce the documented MEntity.
345 super MEntityComposite
348 redef var is_hidden
= false
349 redef var is_toc_hidden
= true
352 # An article that display a ConcernsTreee as a list.
353 class ConcernsArticle
356 # Concerns to list in this article.
357 var concerns
: ConcernsTree
359 redef fun is_hidden
do return concerns
.is_empty
362 # An article that displaus a list of definition belonging to a MEntity.
363 class DefinitionListArticle
368 # An article that display the definition text of a MEntity.
369 class DefinitionArticle
372 redef var is_hidden
= false
375 # The main project article.
381 class ProjectsSection
385 # An article that display an index of mmodules, mclasses and mproperties.
389 # List of mmodules to display.
390 var mmodules
: Array[MModule]
392 # List of mclasses to display.
393 var mclasses
: Array[MClass]
395 # List of mproperties to display.
396 var mprops
: Array[MProperty]
398 redef fun is_hidden
do
399 return mmodules
.is_empty
and mclasses
.is_empty
and mprops
.is_empty