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 mentity
.html_list_item
291 # A card about the linearization of a MEntity
292 class CardLinearizationList
295 # Linearization cards contained in this list
296 var cards
= new Array[CardLinearizationDef] is writable
298 redef var id
= "lin_{super}" is lazy
299 redef var title
= "Linearization" is lazy
301 redef fun rendering
do
302 if cards
.is_empty
then return
304 addn
"<div id='{id}'>"
307 if card
== cards
.last
then break
308 addn
"<h4 class='text-muted text-center'>"
309 addn
" <span class='glyphicon glyphicon-chevron-up'></span>"
316 # A card about a definition in a linearization list
317 class CardLinearizationDef
320 # Is this card displayed by default?
321 var is_active
: Bool = false is optional
, writable
323 # Link to external code repository
325 # Used if `node` is null
326 var url
: nullable String = null is optional
, writable
328 redef var id
= "def_{super}" is lazy
329 redef var title
= mentity
.full_name
is lazy
331 redef fun rendering
do
334 var cin
= if is_active
then "in" else ""
335 var active
= if is_active
then "active" else ""
337 <div class='card {{{active}}}' id='{{{id}}}'>
338 <div class='card-body'>
340 {{{mentity.html_icon.write_to_string}}}
341 {{{mentity.html_namespace.write_to_string}}}"""
344 <div class='btn-bar'>
345 <button class='btn btn-link' data-toggle='collapse'
346 data-target='#{{{mentity.html_id}}}'>
347 <span class='glyphicon glyphicon-console' title='Show code' />
350 else if url
!= null then
352 <div class='btn-bar'>
353 <a class='btn btn-link' href='{{{url}}}'>
354 <span class='glyphicon glyphicon-console' title='Show code' />
357 var mdoc
= mentity
.mdoc
360 addn mdoc
.html_documentation
366 <div id='{{{mentity.html_id}}}' class='collapse {{{cin}}}'>
370 <span class='text-muted'>{{{mentity.location.to_s}}}</span>
379 # A card that displays the code of a MEntity
382 autoinit
(mentity
, node
)
384 # AST node to display in this card
385 var node
: nullable ANode is writable
387 redef var id
= "code_{super}" is lazy
388 redef var title
= "Code"
390 redef fun rendering
do
391 addn
"<div id='{id}' class='card'>"
392 addn
" <div class='card-body'>"
399 addn
"<span class='text-muted'>{mentity.location}</span>"
405 private fun render_code
do
407 if node
== null then return
408 var hl
= new HtmlightVisitor
409 hl
.show_infobox
= false
410 hl
.highlight_node node
415 # A card that displays a graph
418 autoinit
(mentity
, graph
)
420 # Graph to display in this card
421 var graph
: InheritanceGraph is writable
423 redef var id
= "graph_{super}" is lazy
424 redef var title
= "Graph"
426 redef fun rendering
do
427 addn
"<div id='{id}' class='card'>"
428 addn
" <div class='card-body'>"
429 addn
" <div class='text-center'>"
430 addn graph
.graph
.to_svg
437 # Catalog related cards
439 # A card that displays Nit catalog related data
440 abstract class CardCatalog
444 # Catalog used to extract the data
445 var catalog
: Catalog is writable
448 # A card that displays statistics about a Nit catalog
449 class CardCatalogStats
452 redef var id
= "catalog_stats"
453 redef var title
= "Stats"
455 redef fun rendering
do
456 addn
"<div id='{id}' class='container-fluid'>"
457 for key
, value
in catalog
.catalog_stats
.to_map
do
458 addn
"<span class='text-muted small'>"
459 addn
" <strong>{value}</strong> <span>{key}</span> "
467 # A card that displays a list of tags
468 class CardCatalogTags
471 redef var id
= "catalog_tags"
472 redef var title
= "Tags"
474 # Sorter to sort tags alphabetically
475 var tags_sorter
= new CatalogTagsSorter is writable
477 redef fun rendering
do
478 var tags
= catalog
.tag2proj
.keys
.to_a
479 if tags
.is_empty
then return
480 tags_sorter
.sort
(tags
)
482 addn
"<h2 id='{id}'>Tags</h2>"
483 addn
"<div class='container-fluid'>"
485 addn
"<div class='col-xs-6 col-sm-3 col-md-2'>"
486 addn
" <span class='badge'>{catalog.tag2proj[tag].length}</span>"
487 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
495 # A card that displays a package from a Nit catalog
496 class CardCatalogPackage
499 autoinit
(catalog
, mentity
)
501 redef var id
= "package_{super}" is lazy
503 redef fun rendering
do
504 var mpackage
= self.mentity
505 if not mpackage
isa MPackage then return
508 <div id='{{{id}}}' class='card'>
509 <div class='card-left text-center'>{{{mpackage.html_icon.write_to_string}}}</div>
510 <div class='card-body' style='width: 75%'>
511 <h5 class='card-heading'>
512 {{{mentity.html_declaration.write_to_string}}}
514 for tag
in mpackage
.metadata
.tags
do
516 add
"<a href='tag_{tag.to_cmangle}.html' class='text-muted'>{tag}</a>"
517 if tag
!= mpackage
.metadata
.tags
.last
then addn
", "
522 var mdoc
= mentity
.mdoc_or_fallback
525 addn mdoc
.html_documentation
527 addn mdoc
.html_synopsis
531 addn
" <div class='card-right' style='width: 25%'>"
532 for maintainer
in mpackage
.metadata
.maintainers
do
533 addn maintainer
.to_html
536 var license
= mpackage
.metadata
.license
537 if license
!= null then
539 <span class='text-muted'>
540 <a href='http://opensource.org/licenses/{{{license}}}' class='text-muted'>
550 # A card that displays the metadata about a package in the Nit catalog
553 autoinit
(mentity
, metadata
, stats
, deps
, clients
)
555 # Package metadata to display
556 var metadata
: MPackageMetadata is writable
559 var stats
: MPackageStats is writable
561 # Package dependencies
562 var deps
: Array[MPackage] is writable
565 var clients
: Array[MPackage] is writable
567 redef var id
= "metadata_{super}" is lazy
568 redef var title
= "Metadata"
570 redef fun rendering
do
571 for maintainer
in metadata
.maintainers
do
574 {{{maintainer.to_html}}}
577 var license
= metadata
.license
578 if license
!= null then
580 <span class='text-muted'>
581 <a href='http://opensource.org/licenses/{{{license}}}'>{{{license}}}</a>
586 var homepage
= metadata
.homepage
587 var browse
= metadata
.browse
588 var issues
= metadata
.issues
589 if homepage
!= null or browse
!= null or issues
!= null then
592 <ul class='list-unstyled'>"""
593 if homepage
!= null then addn
"<li><a href='{homepage}'>Homepage</a></li>"
594 if browse
!= null then addn
"<li><a href='{browse}'>Source Code</a></li>"
595 if issues
!= null then addn
"<li><a href='{issues}'>Issues</a></li>"
599 var git
= metadata
.git
600 var last_date
= metadata
.last_date
601 var first_date
= metadata
.first_date
605 <ul class='list-unstyled'>
606 <li><a href='{{{git}}}'>{{{git}}}</a></li>
608 <span class='text-muted'><b>{{{stats.commits}}}</b> commits</span>
610 if last_date
!= null then
611 addn
"""<b class=text-muted>Last:</b> {{{last_date}}}<br>"""
613 if first_date
!= null then
614 addn
"""<b class=text-muted>First:</b> {{{first_date}}}"""
620 <ul class='list-unstyled'>
621 <li>{{{stats.documentation_score}}}% documented</li>
624 if metadata
.tags
.not_empty
then
626 for tag
in metadata
.tags
do
627 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
628 if tag
!= metadata
.tags
.last
then add
", "
632 if deps
.not_empty
then
633 addn
"<h4>Dependencies</h4>"
636 if dep
!= deps
.last
then add
", "
640 if clients
.not_empty
then
641 addn
"<h4>Clients</h4>"
642 for client
in clients
do
644 if client
!= clients
.last
then add
", "
648 if metadata
.contributors
.not_empty
then
650 <h4>Contributors</h4>
651 <ul class='list-unstyled'>"""
652 for contrib
in metadata
.contributors
do
653 addn
"""<li>{{{contrib.to_html}}}</li>"""
660 <ul class='list-unstyled'>
661 <li>{{{stats.mmodules}}} modules</li>
662 <li>{{{stats.mclasses}}} classes</li>
663 <li>{{{stats.mmethods}}} methods</li>
664 <li>{{{stats.loc}}} loc</li>