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 pages of the static documentation
16 module static_structure
18 import static
::static_base
22 # Create the structure of this page
23 fun apply_structure
(doc
: DocModel) do end
27 redef fun apply_structure
(doc
) do
28 var title
= doc
.custom_title
or else "Welcome to Nitdoc!"
29 var intro
= doc
.custom_intro
32 main_tab
.content
.add
new CardPageHeader(title
)
33 main_tab
.content
.add
new CardText(intro
)
35 main_tab
.content
.add
new CardPageHeader(title
, "The Nit API documentation.")
38 main_tab
.content
.add
new CardCatalogStats(doc
.catalog
)
39 main_tab
.content
.add
new CardCatalogTags(doc
.catalog
)
41 main_tab
.content
.add
new CardSection(2, "Packages")
42 var mpackages_sorter
= new CatalogScoreSorter(doc
.catalog
)
44 var mpackages
= doc
.catalog
.mpackages
.values
.to_a
45 mpackages_sorter
.sort mpackages
46 var list
= new CardList("packages", "Packages")
47 for mpackage
in mpackages
do
48 list
.cards
.add
new CardCatalogPackage(doc
.catalog
, mpackage
)
51 main_tab
.content
.add list
55 redef class PageMEntity
56 # Concerns to display in this page.
57 var concerns
: nullable ConcernsTree = null
59 redef fun apply_structure
(doc
) do
62 build_dependencies
(doc
)
65 # Build the main tab (the one that contains the MDoc)
66 fun build_main
(doc
: DocModel) do
67 var mentity
= self.mentity
69 var sq
= new CmdSummary(doc
.model
, doc
.filter
, mentity
,
70 markdown_processor
= doc
.inline_processor
)
73 main_tab
.content
.add
new CardMDoc(mentity
, mentity
.mdoc_or_fallback
)
75 var summary
= sq
.summary
76 if summary
!= null then
77 main_tab
.sidebar
.cards
.add
new CardMdSummary(headlines
= summary
, md_processor
= doc
.inline_processor
)
82 fun build_api
(doc
: DocModel) do
83 var summary
= new CardSummary
85 var title
= "All definitions"
86 if mentity
isa MPackage then title
= "All groups and modules"
87 if mentity
isa MGroup then title
= "All subgroups and modules"
88 if mentity
isa MModule then title
= "All class definitions"
89 if mentity
isa MClass or mentity
isa MClassDef then title
= "All properties"
91 var section
= new CardSection(2, title
)
92 api_tab
.content
.add section
93 summary
.cards
.add section
95 var dq
= new CmdFeatures(doc
.model
, doc
.filter
, mentity
)
97 var mentities
= dq
.results
98 if mentities
== null then return
100 var list
= new CardList("api", "API")
101 for m
in mentities
do
102 var card
= new CardMEntity(m
)
103 card
.id
= "api_{card.id}" # avoid id conflicts with main tab
105 summary
.cards
.add card
107 api_tab
.content
.add list
109 if summary
.cards
.not_empty
then
110 api_tab
.sidebar
.cards
.add summary
114 # Build the dependencies tab
115 fun build_dependencies
(doc
: DocModel) do
116 var summary
= new CardSummary
118 var model
= doc
.model
119 var mainmodule
= doc
.mainmodule
120 var filter
= doc
.filter
122 if not doc
.no_dot
then
123 var gq
= new CmdInheritanceGraph(model
, mainmodule
, filter
, mentity
)
126 if graph
!= null then
128 dep_tab
.content
.add
new CardGraph(mentity
, graph
)
132 # No inheritance lists for `Object`
133 if mentity
isa MClass and mentity
.name
== "Object" then return
135 var inh
= new HashMap[String, CmdEntityList]
136 inh
["Ancestors"] = new CmdAncestors(model
, mainmodule
, filter
, mentity
, parents
= false)
137 inh
["Parents"] = new CmdParents(model
, mainmodule
, filter
, mentity
)
138 inh
["Children"] = new CmdChildren(model
, mainmodule
, filter
, mentity
)
139 inh
["Descendants"] = new CmdDescendants(model
, mainmodule
, filter
, mentity
, children
= false)
141 for title
, cmd
in inh
do
143 var results
= cmd
.results
144 if results
== null or results
.is_empty
then continue
145 var section
= new CardSection(3, title
)
146 dep_tab
.content
.add section
147 summary
.cards
.add section
149 var list
= new CardList("inh", "Inheritance")
150 for mentity
in results
do
151 var card
= new CardMEntity(mentity
)
153 summary
.cards
.add card
155 dep_tab
.content
.add list
158 if summary
.cards
.not_empty
then
159 dep_tab
.sidebar
.cards
.add summary
163 # Build the code panel
164 fun build_code
(doc
: DocModel) do
165 var code_url
= doc
.code_url
167 if not doc
.no_code
then
168 var cq
= new CmdEntityCode(doc
.model
, doc
.modelbuilder
, doc
.filter
, mentity
)
172 if code
== null then return
173 code_tab
.content
.add
new CardCode(mentity
, code
)
174 else if doc
.code_url
!= null then
175 code_tab
= new DocTabLink("code", "Code", "console", mentity
.source_url
(code_url
))
179 # Build the linearization panel
180 fun build_linearization
(doc
: DocModel) do
181 var summary
= new CardSummary
183 var lq
= new CmdLinearization(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
186 var mentities
= lq
.results
187 if mentities
== null then return
189 if mentity
isa MClass or mentity
isa MClassDef then
190 if mentity
.name
== "Object" then return # No linearization for `Object`
191 if mentity
.name
== "Sys" then return # No linearization for `Sys`
192 var section
= new CardSection(2, "Class definitions")
193 lin_tab
.content
.add section
194 summary
.cards
.add section
195 else if mentity
isa MProperty or mentity
isa MPropDef then
196 if mentity
.name
== "init" then return # No linearization for `init`
197 if mentity
.name
== "SELF" then return # No linearization for `SELF`
198 if mentity
.name
== "to_s" then return # No linearization for `to_s`
199 var section
= new CardSection(2, "Property definitions")
200 lin_tab
.content
.add section
201 summary
.cards
.add section
204 var list
= new CardLinearizationList(mentity
)
205 for m
in mentities
do
206 var url
= mentity
.source_url
(doc
.code_url
)
207 var node
= doc
.modelbuilder
.mentity2node
(m
)
208 if node
== null then continue
209 if doc
.no_code
then node
= null
211 (m
isa MClassDef and m
.is_intro
) or
212 (m
isa MPropDef and m
.is_intro
) then
213 var card
= new CardLinearizationDef(m
, node
, is_active
= true, url
)
215 summary
.cards
.add card
217 var card
= new CardLinearizationDef(m
, node
, is_active
= false, url
)
219 summary
.cards
.add card
222 lin_tab
.content
.add list
224 if summary
.cards
.not_empty
then
225 lin_tab
.sidebar
.cards
.add summary
230 redef class PageMPackage
231 redef fun build_main
(doc
) do
233 main_tab
.metadata
.cards
.add
new CardMetadata(mentity
, mentity
.metadata
,
234 doc
.catalog
.mpackages_stats
[mentity
],
235 doc
.catalog
.deps
[mentity
].direct_greaters
.to_a
,
236 doc
.catalog
.deps
[mentity
].direct_smallers
.to_a
)
240 redef class PageMModule
241 redef fun apply_structure
(doc
) do
246 redef fun build_main
(doc
) do
249 var summary
= new CardSummary(no_title
= true)
252 var cmd
: CmdEntities = new CmdIntros(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
254 var intros
= cmd
.results
255 if intros
!= null and intros
.not_empty
then
256 var section
= new CardSection(3, "Introduced classes")
257 main_tab
.content
.add section
258 summary
.cards
.add section
259 var cards
= new CardList("intros", "Intros")
260 for intro
in intros
do
261 var card
= new CardMEntity(intro
)
262 summary
.cards
.add card
265 main_tab
.content
.add cards
269 cmd
= new CmdRedefs(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
271 var redefs
= cmd
.results
272 if redefs
!= null and redefs
.not_empty
then
273 var section
= new CardSection(3, "Redefined classes")
274 main_tab
.content
.add section
275 summary
.cards
.add section
276 var cards
= new CardList("redefs", "Redefs")
277 for prop
in redefs
do
278 var card
= new CardMEntity(prop
)
279 summary
.cards
.add card
282 main_tab
.content
.add cards
285 main_tab
.sidebar
.cards
.add summary
289 redef class PageMClass
290 redef fun apply_structure
(doc
) do
293 build_linearization
(doc
)
296 redef fun build_main
(doc
) do
299 var summary
= new CardSummary(no_title
= true)
302 var cmd
: CmdEntities = new CmdIntros(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
304 var intros
= cmd
.results
305 if intros
!= null and intros
.not_empty
then
306 var section
= new CardSection(3, "Introduced properties")
307 main_tab
.content
.add section
308 summary
.cards
.add section
309 var cards
= new CardList("intros", "Intros")
310 for intro
in intros
do
311 var card
= new CardMEntity(intro
)
312 summary
.cards
.add card
315 main_tab
.content
.add cards
319 cmd
= new CmdRedefs(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
321 var redefs
= cmd
.results
322 if redefs
!= null and redefs
.not_empty
then
323 var section
= new CardSection(3, "Redefined properties")
324 main_tab
.content
.add section
325 summary
.cards
.add section
326 var cards
= new CardList("redefs", "Redefs")
327 for prop
in redefs
do
328 var card
= new CardMEntity(prop
)
329 summary
.cards
.add card
332 main_tab
.content
.add cards
336 main_tab
.sidebar
.cards
.add summary
339 redef fun build_api
(doc
) do
340 var summary
= new CardSummary
342 var section
= new CardSection(2, "All properties")
343 api_tab
.content
.add section
344 summary
.cards
.add section
346 var dq
= new CmdAllProps(doc
.model
, doc
.mainmodule
, doc
.filter
, mentity
)
348 var mentities
= dq
.results
349 if mentities
== null then return
351 var list
= new CardList("api", "API")
352 for m
in mentities
do
353 var card
= new CardMEntity(m
)
355 summary
.cards
.add card
357 api_tab
.content
.add list
359 if summary
.cards
.not_empty
then
360 api_tab
.sidebar
.cards
.add summary
365 redef class PageMProperty
366 redef fun apply_structure
(doc
) do
369 build_linearization
(doc
)
373 redef class PagePerson
374 redef fun apply_structure
(doc
) do
375 var mpackages_sorter
= new CatalogScoreSorter(doc
.catalog
)
376 main_tab
.content
.add
new CardPageHeader(person
.name
, person
.email
)
378 var maint
= doc
.catalog
.maint2proj
[person
]
379 mpackages_sorter
.sort maint
380 var mlist
= new CardList("maintained", "Maintained")
381 for mpackage
in maint
do
382 mlist
.cards
.add
new CardCatalogPackage(doc
.catalog
, mpackage
)
386 if maint
.not_empty
then
387 main_tab
.content
.add
new CardSection(3, "{maint.length} maintained packages")
388 main_tab
.content
.add mlist
391 var contrib
= doc
.catalog
.contrib2proj
[person
]
392 mpackages_sorter
.sort contrib
393 var clist
= new CardList("contribs", "Contributed")
394 for mpackage
in contrib
do
395 clist
.cards
.add
new CardCatalogPackage(doc
.catalog
, mpackage
)
399 if contrib
.not_empty
then
400 main_tab
.content
.add
new CardSection(3, "{contrib.length} contributed packages")
401 main_tab
.content
.add clist
407 redef fun apply_structure
(doc
) do
408 var mpackages_sorter
= new CatalogScoreSorter(doc
.catalog
)
409 main_tab
.content
.add
new CardPageHeader(tag
)
411 var mpackages
= doc
.catalog
.tag2proj
[tag
]
412 mpackages_sorter
.sort mpackages
413 var list
= new CardList("packages", "Packages")
414 for mpackage
in mpackages
do
415 list
.cards
.add
new CardCatalogPackage(doc
.catalog
, mpackage
)
419 main_tab
.content
.add
new CardSection(3, "{mpackages.length} packages")
420 main_tab
.content
.add list
425 # Render a HTML link for the MEntity location
426 private fun source_url
(url_pattern
: nullable String): String do
427 var location
= self.location
428 var file
= location
.file
430 if file
== null then return location
.to_s
431 if url_pattern
== null then return file
.filename
.simplify_path
433 var url
= url_pattern
434 url
= url
.replace
("%f", file
.filename
.simplify_path
)
435 url
= url
.replace
("%l", location
.line_start
.to_s
)
436 url
= url
.replace
("%L", location
.line_end
.to_s
)
437 return url
.simplify_path