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
)
38 # TODO index and search page should also be structured here
43 # Populates `self` with structure elements like DocComposite ones.
45 # See `StructurePhase`.
46 fun apply_structure
(v
: StructurePhase, doc
: DocModel) do end
49 redef class OverviewPage
50 redef fun apply_structure
(v
, doc
) do
51 var article
= new HomeArticle
52 root
.add_child article
54 var mprojects
= doc
.model
.mprojects
.to_a
55 var sorter
= new MConcernRankSorter
57 var section
= new ProjectsSection
58 for mproject
in mprojects
do
59 section
.add_child
new DefinitionArticle(mproject
)
61 article
.add_child section
65 redef class MGroupPage
66 redef fun apply_structure
(v
, doc
) do
67 var section
= new MEntitySection(mentity
)
68 root
.add_child section
69 if mentity
.is_root
then
70 section
.add_child
new IntroArticle(mentity
.mproject
)
72 section
.add_child
new IntroArticle(mentity
)
74 var concerns
= self.concerns
75 if concerns
== null or concerns
.is_empty
then return
77 mentity
.mproject
.booster_rank
= -1000
78 mentity
.booster_rank
= -1000
79 concerns
.sort_with
(v
.concerns_sorter
)
80 mentity
.mproject
.booster_rank
= 0
81 mentity
.booster_rank
= 0
82 section
.add_child
new ConcernsArticle(mentity
, concerns
)
83 for mentity
in concerns
do
84 if mentity
isa MModule then
85 section
.add_child
new DefinitionArticle(mentity
)
87 section
.add_child
new ConcernSection(mentity
)
93 redef class MModulePage
94 redef fun apply_structure
(v
, doc
) do
95 var section
= new MEntitySection(mentity
)
96 root
.add_child section
97 section
.add_child
new IntroArticle(mentity
)
98 var concerns
= self.concerns
99 if concerns
== null or concerns
.is_empty
then return
101 mentity
.mgroup
.mproject
.booster_rank
= -1000
102 mentity
.mgroup
.booster_rank
= -1000
103 mentity
.booster_rank
= -1000
104 concerns
.sort_with
(v
.concerns_sorter
)
105 mentity
.mgroup
.mproject
.booster_rank
= 0
106 mentity
.mgroup
.booster_rank
= 0
107 mentity
.booster_rank
= 0
108 section
.add_child
new ConcernsArticle(mentity
, concerns
)
110 for mentity
in concerns
do
111 var ssection
= new ConcernSection(mentity
)
112 if mentity
isa MModule then
113 var mclasses
= mclasses_for_mmodule
(mentity
).to_a
114 v
.name_sorter
.sort
(mclasses
)
115 for mclass
in mclasses
do
116 var article
= new DefinitionArticle(mclass
)
117 var mclassdefs
= mclassdefs_for
(mclass
).to_a
118 if not mclassdefs
.has
(mclass
.intro
) then
119 article
.add_child
(new DefinitionArticle(mclass
.intro
))
121 doc
.mainmodule
.linearize_mclassdefs
(mclassdefs
)
122 for mclassdef
in mclassdefs
do
123 article
.add_child
(new DefinitionArticle(mclassdef
))
125 ssection
.add_child article
128 section
.add_child ssection
132 # Filters `self.mclassses` by intro `mmodule`.
133 private fun mclasses_for_mmodule
(mmodule
: MModule): Set[MClass] do
134 var mclasses
= new HashSet[MClass]
135 for mclass
in self.mclasses
do
136 if mclass
.intro
.mmodule
== mmodule
then
143 # Filters `self.mclassdefs` by `mclass`.
144 private fun mclassdefs_for
(mclass
: MClass): Set[MClassDef] do
145 var mclassdefs
= new HashSet[MClassDef]
146 for mclassdef
in self.mclassdefs
do
147 if mclassdef
.mclass
== mclass
then
148 mclassdefs
.add mclassdef
155 redef class MClassPage
156 redef fun apply_structure
(v
, doc
) do
157 var section
= new MEntitySection(mentity
)
158 root
.add_child section
159 section
.add_child
new IntroArticle(mentity
)
160 var concerns
= self.concerns
161 if concerns
== null or concerns
.is_empty
then return
163 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= -1000
164 mentity
.intro_mmodule
.mgroup
.booster_rank
= -1000
165 mentity
.intro_mmodule
.booster_rank
= -1000
166 concerns
.sort_with
(v
.concerns_sorter
)
167 mentity
.intro_mmodule
.mgroup
.mproject
.booster_rank
= 0
168 mentity
.intro_mmodule
.mgroup
.booster_rank
= 0
169 mentity
.intro_mmodule
.booster_rank
= 0
170 section
.add_child
new ConcernsArticle(mentity
, concerns
)
171 for mentity
in concerns
do
172 var ssection
= new ConcernSection(mentity
)
173 if mentity
isa MModule then
174 var mprops
= mproperties_for
(mentity
)
175 var by_kind
= new PropertiesByKind.with_elements
(mprops
)
176 for group
in by_kind
.groups
do
177 v
.name_sorter
.sort
(group
)
178 for mprop
in group
do
179 for mpropdef
in mpropdefs_for
(mprop
, mentity
) do
180 ssection
.add_child
new DefinitionArticle(mpropdef
)
185 section
.add_child ssection
189 # Filters `self.mpropdefs` by `mmodule`.
192 private fun mproperties_for
(mmodule
: MModule): Set[MProperty] do
193 var mprops
= new HashSet[MProperty]
194 for mpropdef
in self.mpropdefs
do
195 if mpropdef
.mclassdef
.mmodule
== mmodule
then
196 mprops
.add mpropdef
.mproperty
202 # Filters `self.mpropdefs` by `mproperty`.
205 private fun mpropdefs_for
(mproperty
: MProperty, mmodule
: MModule): Set[MPropDef] do
206 var mpropdefs
= new HashSet[MPropDef]
207 for mpropdef
in self.mpropdefs
do
208 if mpropdef
.mproperty
== mproperty
and
209 mpropdef
.mclassdef
.mmodule
== mmodule
then
210 mpropdefs
.add mpropdef
217 redef class MPropertyPage
218 redef fun apply_structure
(v
, doc
) do
219 var section
= new MEntitySection(mentity
)
220 root
.add_child section
221 section
.add_child
new IntroArticle(mentity
)
222 var concerns
= self.concerns
223 if concerns
== null or concerns
.is_empty
then return
225 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= -1000
226 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= -1000
227 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= -1000
228 concerns
.sort_with
(v
.concerns_sorter
)
229 mentity
.intro
.mclassdef
.mmodule
.mgroup
.mproject
.booster_rank
= 0
230 mentity
.intro
.mclassdef
.mmodule
.mgroup
.booster_rank
= 0
231 mentity
.intro
.mclassdef
.mmodule
.booster_rank
= 0
232 section
.add_child
new ConcernsArticle(mentity
, concerns
)
233 for mentity
in concerns
do
234 var ssection
= new ConcernSection(mentity
)
235 if mentity
isa MModule then
237 var mpropdefs
= mpropdefs_for
(mentity
).to_a
238 v
.name_sorter
.sort
(mpropdefs
)
239 for mpropdef
in mpropdefs
do
240 ssection
.add_child
new DefinitionArticle(mpropdef
)
243 section
.add_child ssection
247 # Filters `self.mpropdefs` by `mmodule`.
248 private fun mpropdefs_for
(mmodule
: MModule): Set[MPropDef] do
249 var mpropdefs
= new HashSet[MPropDef]
250 for mpropdef
in self.mpropdefs
do
251 if mpropdef
.mclassdef
.mmodule
== mmodule
then
252 mpropdefs
.add mpropdef
259 # A DocComposite element about a MEntity.
260 class MEntityComposite
263 # MEntity documented by this page element.
267 # A Section about a Concern.
269 # Those sections are used to build the page summary.
271 super MEntityComposite
275 # An article about a Mentity.
277 # Used to display textual content about a MEntity.
278 abstract class MEntityArticle
279 super MEntityComposite
283 # A section about a Mentity.
285 # Used to regroup content about a MEntity.
287 super MEntityComposite
291 # An introduction article about a MEntity.
293 # Used at the top of a documentation page to introduce the documented MEntity.
295 super MEntityComposite
299 # An article that display a ConcernsTreee as a list.
300 class ConcernsArticle
303 # Concerns to list in this article.
304 var concerns
: ConcernsTree
307 # An article that display the definition text of a MEntity.
308 class DefinitionArticle
312 # The main project article.
318 class ProjectsSection