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 # Cards templates for the static documentation
18 import doc
::commands
::commands_graph
19 import doc
::commands
::commands_catalog
20 import doc
::commands
::commands_docdown
23 # A card that can be rendered to HTML
25 # Basically, these cards are templates with additionnal data and behavior.
26 abstract class StaticCard
30 var title
: String is writable
33 var id
: String is writable
40 # Cards contained in this list
41 var cards
= new Array[StaticCard] is writable
43 redef fun rendering
do
44 addn
"<div id='{id}' class='card-list'>"
54 # A card that display custom text data
59 # Custom content from options
60 var content
: nullable String is writable
63 redef var title
= "Home"
65 redef fun rendering
do
66 var content
= self.content
67 if content
== null then return
77 # It displays an heading at a specific level from 1 to 6.
80 autoinit
(level
, title
, subtitle
)
82 # Section heading level
83 var level
: Int is writable
86 var subtitle
: nullable String is writable
88 redef var id
= title
.to_cmangle
is lazy
90 redef fun rendering
do
91 addn
"<h{level} id='{id}'>{title}</h{level}>"
98 autoinit
(title
, subtitle
)
102 redef fun rendering
do
103 addn
"<div class='page-header'>"
105 var subtitle
= self.subtitle
106 if subtitle
!= null then
107 addn
"<p class='text-muted'>"
115 # A card that displays a summary of a list of cards
120 redef var id
= "summary"
121 redef var title
= "Summary"
123 # Show the summary title
124 var no_title
: Bool = false is optional
, writable
126 redef fun rendering
do
128 addn
"<h4>Summary</h4>"
130 addn
"<div class='summary'>"
131 addn
" <ul class='list-unstyled'>"
132 var sections
= new Array[CardSection]
134 if card
isa CardSection then
135 while sections
.not_empty
and sections
.last
.level
>= card
.level
do
140 var level
= if sections
.is_empty
then 1 else sections
.last
.level
141 if not card
isa CardSection then level
+= 1
142 addn
"<li><a href='#{card.id}'><h{level}>{card.title}</h{level}></a></li>"
149 # A card that displays the summary of a Markdown document
152 autoinit
(md_processor
, headlines
)
154 # Markdown processor used to extract and render the content
155 var md_processor
: MarkdownProcessor is writable
157 # Headlines found in the document
158 var headlines
: ArrayMap[String, HeadLine] is writable
160 redef var id
= "summary"
161 redef var title
= "Summary"
163 redef fun rendering
do
164 addn
"<h4>Summary</h4>"
165 addn
"<div class='summary'>"
166 addn
" <ul class='list-unstyled'>"
167 for id
, headline
in headlines
do
168 var level
= headline
.level
169 var title
= md_processor
.process
(headline
.title
)
170 addn
"<li><a href='#{id}'><h{level}>{title}</h{level}></a></li>"
177 # MEntity related cards
179 # A card about a mentity
181 # It displays the documentation about the model entity.
184 autoinit
(mentity
, full_doc
)
186 # MEntity displayed in this card
187 var mentity
: MEntity is writable
189 # Render the mentity full documentation?
190 var full_doc
= false is optional
, writable
192 redef var id
= mentity
.html_id
is lazy
193 redef var title
= mentity
.html_name
is lazy
195 redef fun rendering
do
197 <div id='{{{id}}}' class='card'>
198 <div class='card-left text-center'>
199 {{{mentity.html_icon.write_to_string}}}
201 <div class='card-body'>
202 <h5 class='card-heading'>
203 {{{mentity.html_declaration.write_to_string}}}
205 <p><small>{{{mentity.html_namespace.write_to_string}}}</small></p>"""
206 var mdoc
= mentity
.mdoc_or_fallback
209 addn mdoc
.html_documentation
211 addn mdoc
.html_synopsis
220 # A card that displays the content of a MDoc
223 autoinit
(mentity
, mdoc
, full_doc
)
225 # MDoc to display in this card
226 var mdoc
: nullable MDoc is writable
228 redef fun rendering
do
230 if mdoc
== null then return
231 addn
"<div id='{id}' class='card'>"
232 addn
" <div class='card-body nitdoc'>"
233 addn mdoc
.html_documentation
239 # A card about the inheritance of a MEntity
240 class CardInheritance
244 var ancestors
: nullable Array[MEntity] is writable
247 var parents
: nullable Array[MEntity] is writable
250 var children
: nullable Array[MEntity] is writable
253 var descendants
: nullable Array[MEntity] is writable
255 redef var id
= "inh_{super}" is lazy
256 redef var title
= "Inheritance" is lazy
258 redef fun rendering
do
259 var ancestors
= self.ancestors
260 var descendants
= self.descendants
261 if ancestors
== null and parents
== null and
262 children
== null and descendants
== null then return
264 addn
"<div id='{id}' class='card'>"
265 addn
" <div class='card-body'>"
266 if ancestors
!= null and ancestors
.length
<= 10 then
267 render_list
("Ancestors", ancestors
)
269 render_list
("Parents", parents
)
271 if descendants
!= null and descendants
.length
<= 10 then
272 render_list
("Descendants", descendants
)
274 render_list
("Children", children
)
280 private fun render_list
(title
: String, mentities
: nullable Array[MEntity]) do
281 if mentities
== null or mentities
.is_empty
then return
282 addn
"<h4 id='{id}'>{title}</h4>"
283 addn
"<ul class='list-unstyled'>"
284 for mentity
in mentities
do
285 addn html_list_item
(mentity
)
290 private fun html_list_item
(mentity
: MEntity): ListItem do
291 var tpl
= new Template
292 tpl
.add mentity
.html_namespace
293 var comment
= mentity
.mdoc_or_fallback
294 if comment
!= null then
296 tpl
.add comment
.html_synopsis
298 return new ListItem(tpl
)
302 # A card about the linearization of a MEntity
303 class CardLinearizationList
306 # Linearization cards contained in this list
307 var cards
= new Array[CardLinearizationDef] is writable
309 redef var id
= "lin_{super}" is lazy
310 redef var title
= "Linearization" is lazy
312 redef fun rendering
do
313 if cards
.is_empty
then return
315 addn
"<div id='{id}'>"
318 if card
== cards
.last
then break
319 addn
"<h4 class='text-muted text-center'>"
320 addn
" <span class='glyphicon glyphicon-chevron-up'></span>"
327 # A card about a definition in a linearization list
328 class CardLinearizationDef
331 # Is this card displayed by default?
332 var is_active
: Bool = false is optional
, writable
334 # Link to external code repository
336 # Used if `node` is null
337 var url
: nullable String = null is optional
, writable
339 redef var id
= "def_{super}" is lazy
340 redef var title
= mentity
.full_name
is lazy
342 redef fun rendering
do
345 var cin
= if is_active
then "in" else ""
346 var active
= if is_active
then "active" else ""
348 <div class='card {{{active}}}' id='{{{id}}}'>
349 <div class='card-body'>
351 {{{mentity.html_icon.write_to_string}}}
352 {{{mentity.html_namespace.write_to_string}}}"""
355 <div class='btn-bar'>
356 <button class='btn btn-link' data-toggle='collapse'
357 data-target='#{{{mentity.html_id}}}'>
358 <span class='glyphicon glyphicon-console' title='Show code' />
361 else if url
!= null then
363 <div class='btn-bar'>
364 <a class='btn btn-link' href='{{{url}}}'>
365 <span class='glyphicon glyphicon-console' title='Show code' />
368 var mdoc
= mentity
.mdoc
371 addn mdoc
.html_documentation
377 <div id='{{{mentity.html_id}}}' class='collapse {{{cin}}}'>
381 <span class='text-muted'>{{{mentity.location.to_s}}}</span>
390 # A card that displays the code of a MEntity
393 autoinit
(mentity
, node
)
395 # AST node to display in this card
396 var node
: nullable ANode is writable
398 redef var id
= "code_{super}" is lazy
399 redef var title
= "Code"
401 redef fun rendering
do
402 addn
"<div id='{id}' class='card'>"
403 addn
" <div class='card-body'>"
410 addn
"<span class='text-muted'>{mentity.location}</span>"
416 private fun render_code
do
418 if node
== null then return
419 var hl
= new HtmlightVisitor
420 hl
.show_infobox
= false
421 hl
.highlight_node node
426 # A card that displays a graph
429 autoinit
(mentity
, graph
)
431 # Graph to display in this card
432 var graph
: InheritanceGraph is writable
434 redef var id
= "graph_{super}" is lazy
435 redef var title
= "Graph"
437 redef fun rendering
do
438 addn
"<div id='{id}' class='card'>"
439 addn
" <div class='card-body'>"
440 addn
" <div class='text-center'>"
441 addn graph
.graph
.to_svg
448 # Catalog related cards
450 # A card that displays Nit catalog related data
451 abstract class CardCatalog
455 # Catalog used to extract the data
456 var catalog
: Catalog is writable
459 # A card that displays statistics about a Nit catalog
460 class CardCatalogStats
463 redef var id
= "catalog_stats"
464 redef var title
= "Stats"
466 redef fun rendering
do
467 addn
"<div id='{id}' class='container-fluid'>"
468 for key
, value
in catalog
.catalog_stats
.to_map
do
469 addn
"<span class='text-muted small'>"
470 addn
" <strong>{value}</strong> <span>{key}</span> "
478 # A card that displays a list of tags
479 class CardCatalogTags
482 redef var id
= "catalog_tags"
483 redef var title
= "Tags"
485 # Sorter to sort tags alphabetically
486 var tags_sorter
= new CatalogTagsSorter is writable
488 redef fun rendering
do
489 var tags
= catalog
.tag2proj
.keys
.to_a
490 if tags
.is_empty
then return
491 tags_sorter
.sort
(tags
)
493 addn
"<h2 id='{id}'>Tags</h2>"
494 addn
"<div class='container-fluid'>"
496 addn
"<div class='col-xs-6 col-sm-3 col-md-2'>"
497 addn
" <span class='badge'>{catalog.tag2proj[tag].length}</span>"
498 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
506 # A card that displays a package from a Nit catalog
507 class CardCatalogPackage
510 autoinit
(catalog
, mentity
)
512 redef var id
= "package_{super}" is lazy
514 redef fun rendering
do
515 var mpackage
= self.mentity
516 if not mpackage
isa MPackage then return
519 <div id='{{{id}}}' class='card'>
520 <div class='card-left text-center'>{{{mpackage.html_icon.write_to_string}}}</div>
521 <div class='card-body' style='width: 75%'>
522 <h5 class='card-heading'>
523 {{{mentity.html_declaration.write_to_string}}}
525 for tag
in mpackage
.metadata
.tags
do
527 add
"<a href='tag_{tag.to_cmangle}.html' class='text-muted'>{tag}</a>"
528 if tag
!= mpackage
.metadata
.tags
.last
then addn
", "
533 var mdoc
= mentity
.mdoc_or_fallback
536 addn mdoc
.html_documentation
538 addn mdoc
.html_synopsis
542 addn
" <div class='card-right' style='width: 25%'>"
543 for maintainer
in mpackage
.metadata
.maintainers
do
544 addn maintainer
.to_html
547 var license
= mpackage
.metadata
.license
548 if license
!= null then
550 <span class='text-muted'>
551 <a href='http://opensource.org/licenses/{{{license}}}' class='text-muted'>
561 # A card that displays the metadata about a package in the Nit catalog
564 autoinit
(mentity
, metadata
, stats
, deps
, clients
)
566 # Package metadata to display
567 var metadata
: MPackageMetadata is writable
570 var stats
: MPackageStats is writable
572 # Package dependencies
573 var deps
: Array[MPackage] is writable
576 var clients
: Array[MPackage] is writable
578 redef var id
= "metadata_{super}" is lazy
579 redef var title
= "Metadata"
581 redef fun rendering
do
582 for maintainer
in metadata
.maintainers
do
585 {{{maintainer.to_html}}}
588 var license
= metadata
.license
589 if license
!= null then
591 <span class='text-muted'>
592 <a href='http://opensource.org/licenses/{{{license}}}'>{{{license}}}</a>
597 var homepage
= metadata
.homepage
598 var browse
= metadata
.browse
599 var issues
= metadata
.issues
600 if homepage
!= null or browse
!= null or issues
!= null then
603 <ul class='list-unstyled'>"""
604 if homepage
!= null then addn
"<li><a href='{homepage}'>Homepage</a></li>"
605 if browse
!= null then addn
"<li><a href='{browse}'>Source Code</a></li>"
606 if issues
!= null then addn
"<li><a href='{issues}'>Issues</a></li>"
610 var git
= metadata
.git
611 var last_date
= metadata
.last_date
612 var first_date
= metadata
.first_date
616 <ul class='list-unstyled'>
617 <li><a href='{{{git}}}'>{{{git}}}</a></li>
619 <span class='text-muted'><b>{{{stats.commits}}}</b> commits</span>
621 if last_date
!= null then
622 addn
"""<b class=text-muted>Last:</b> {{{last_date}}}<br>"""
624 if first_date
!= null then
625 addn
"""<b class=text-muted>First:</b> {{{first_date}}}"""
631 <ul class='list-unstyled'>
632 <li>{{{stats.documentation_score}}}% documented</li>
635 if metadata
.tags
.not_empty
then
637 for tag
in metadata
.tags
do
638 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
639 if tag
!= metadata
.tags
.last
then add
", "
643 if deps
.not_empty
then
644 addn
"<h4>Dependencies</h4>"
647 if dep
!= deps
.last
then add
", "
651 if clients
.not_empty
then
652 addn
"<h4>Clients</h4>"
653 for client
in clients
do
655 if client
!= clients
.last
then add
", "
659 if metadata
.contributors
.not_empty
then
661 <h4>Contributors</h4>
662 <ul class='list-unstyled'>"""
663 for contrib
in metadata
.contributors
do
664 addn
"""<li>{{{contrib.to_html}}}</li>"""
671 <ul class='list-unstyled'>
672 <li>{{{stats.mmodules}}} modules</li>
673 <li>{{{stats.mclasses}}} classes</li>
674 <li>{{{stats.mmethods}}} methods</li>
675 <li>{{{stats.loc}}} loc</li>