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 templates
::html_commands
20 # A card that can be rendered to HTML
22 # Basically, these cards are templates with additionnal data and behavior.
23 abstract class StaticCard
27 var title
: String is writable
30 var id
: String is writable
37 # Cards contained in this list
38 var cards
= new Array[StaticCard] is writable
40 redef fun rendering
do
41 addn
"<div id='{id}' class='card-list'>"
51 # A card that display custom text data
56 # Custom content from options
57 var content
: nullable String is writable
60 redef var title
= "Home"
62 redef fun rendering
do
63 var content
= self.content
64 if content
== null then return
74 # It displays an heading at a specific level from 1 to 6.
77 autoinit
(level
, title
, subtitle
)
79 # Section heading level
80 var level
: Int is writable
83 var subtitle
: nullable String is writable
85 redef var id
= title
.to_cmangle
is lazy
87 redef fun rendering
do
88 addn
"<h{level} id='{id}'>{title}</h{level}>"
95 autoinit
(title
, subtitle
)
99 redef fun rendering
do
100 addn
"<div class='page-header'>"
102 var subtitle
= self.subtitle
103 if subtitle
!= null then
104 addn
"<p class='text-muted'>"
112 # A card that displays a summary of a list of cards
117 redef var id
= "summary"
118 redef var title
= "Summary"
120 # Show the summary title
121 var no_title
: Bool = false is optional
, writable
123 redef fun rendering
do
125 addn
"<h4>Summary</h4>"
127 addn
"<div class='summary'>"
128 addn
" <ul class='list-unstyled'>"
129 var sections
= new Array[CardSection]
131 if card
isa CardSection then
132 while sections
.not_empty
and sections
.last
.level
>= card
.level
do
137 var level
= if sections
.is_empty
then 1 else sections
.last
.level
138 if not card
isa CardSection then level
+= 1
139 addn
"<li><a href='#{card.id}'><h{level}>{card.title}</h{level}></a></li>"
146 # A card that displays the summary of a Markdown document
149 autoinit
(md_processor
, headlines
)
151 # Markdown processor used to extract and render the content
152 var md_processor
: MarkdownProcessor is writable
154 # Headlines found in the document
155 var headlines
: ArrayMap[String, HeadLine] is writable
157 redef var id
= "summary"
158 redef var title
= "Summary"
160 redef fun rendering
do
161 addn
"<h4>Summary</h4>"
162 addn
"<div class='summary'>"
163 addn
" <ul class='list-unstyled'>"
164 for id
, headline
in headlines
do
165 var level
= headline
.level
166 var title
= md_processor
.process
(headline
.title
)
167 addn
"<li><a href='#{id}'><h{level}>{title}</h{level}></a></li>"
174 # MEntity related cards
176 # A card about a mentity
178 # It displays the documentation about the model entity.
181 autoinit
(mentity
, full_doc
)
183 # MEntity displayed in this card
184 var mentity
: MEntity is writable
186 # Render the mentity full documentation?
187 var full_doc
= false is optional
, writable
189 redef var id
= mentity
.html_id
is lazy
190 redef var title
= mentity
.html_name
is lazy
192 redef fun rendering
do
194 <div id='{{{id}}}' class='card'>
195 <div class='card-left text-center'>
196 {{{mentity.html_icon.write_to_string}}}
198 <div class='card-body'>
199 <h5 class='card-heading'>
200 {{{mentity.html_declaration.write_to_string}}}
202 <p><small>{{{mentity.html_namespace.write_to_string}}}</small></p>"""
203 var mdoc
= mentity
.mdoc_or_fallback
206 addn mdoc
.html_documentation
208 addn mdoc
.html_synopsis
217 # A card that displays the content of a MDoc
220 autoinit
(mentity
, mdoc
, full_doc
)
222 # MDoc to display in this card
223 var mdoc
: nullable MDoc is writable
225 redef fun rendering
do
227 if mdoc
== null then return
228 addn
"<div id='{id}' class='card'>"
229 addn
" <div class='card-body nitdoc'>"
230 addn mdoc
.html_documentation
236 # A card about the inheritance of a MEntity
237 class CardInheritance
241 var ancestors
: nullable Array[MEntity] is writable
244 var parents
: nullable Array[MEntity] is writable
247 var children
: nullable Array[MEntity] is writable
250 var descendants
: nullable Array[MEntity] is writable
252 redef var id
= "inh_{super}" is lazy
253 redef var title
= "Inheritance" is lazy
255 redef fun rendering
do
256 var ancestors
= self.ancestors
257 var descendants
= self.descendants
258 if ancestors
== null and parents
== null and
259 children
== null and descendants
== null then return
261 addn
"<div id='{id}' class='card'>"
262 addn
" <div class='card-body'>"
263 if ancestors
!= null and ancestors
.length
<= 10 then
264 render_list
("Ancestors", ancestors
)
266 render_list
("Parents", parents
)
268 if descendants
!= null and descendants
.length
<= 10 then
269 render_list
("Descendants", descendants
)
271 render_list
("Children", children
)
277 private fun render_list
(title
: String, mentities
: nullable Array[MEntity]) do
278 if mentities
== null or mentities
.is_empty
then return
279 addn
"<h4 id='{id}'>{title}</h4>"
280 addn
"<ul class='list-unstyled'>"
281 for mentity
in mentities
do
282 addn html_list_item
(mentity
)
287 private fun html_list_item
(mentity
: MEntity): ListItem do
288 var tpl
= new Template
289 tpl
.add mentity
.html_namespace
290 var comment
= mentity
.mdoc_or_fallback
291 if comment
!= null then
293 tpl
.add comment
.html_synopsis
295 return new ListItem(tpl
)
299 # A card about the linearization of a MEntity
300 class CardLinearizationList
303 # Linearization cards contained in this list
304 var cards
= new Array[CardLinearizationDef] is writable
306 redef var id
= "lin_{super}" is lazy
307 redef var title
= "Linearization" is lazy
309 redef fun rendering
do
310 if cards
.is_empty
then return
312 addn
"<div id='{id}'>"
315 if card
== cards
.last
then break
316 addn
"<h4 class='text-muted text-center'>"
317 addn
" <span class='glyphicon glyphicon-chevron-up'></span>"
324 # A card about a definition in a linearization list
325 class CardLinearizationDef
328 # Is this card displayed by default?
329 var is_active
: Bool = false is optional
, writable
331 # Link to external code repository
333 # Used if `node` is null
334 var url
: nullable String = null is optional
, writable
336 redef var id
= "def_{super}" is lazy
337 redef var title
= mentity
.full_name
is lazy
339 redef fun rendering
do
342 var cin
= if is_active
then "in" else ""
343 var active
= if is_active
then "active" else ""
345 <div class='card {{{active}}}' id='{{{id}}}'>
346 <div class='card-body'>
348 {{{mentity.html_icon.write_to_string}}}
349 {{{mentity.html_namespace.write_to_string}}}"""
352 <div class='btn-bar'>
353 <button class='btn btn-link' data-toggle='collapse'
354 data-target='#{{{mentity.html_id}}}'>
355 <span class='glyphicon glyphicon-console' title='Show code' />
358 else if url
!= null then
360 <div class='btn-bar'>
361 <a class='btn btn-link' href='{{{url}}}'>
362 <span class='glyphicon glyphicon-console' title='Show code' />
365 var mdoc
= mentity
.mdoc
368 addn mdoc
.html_documentation
374 <div id='{{{mentity.html_id}}}' class='collapse {{{cin}}}'>
378 <span class='text-muted'>{{{mentity.location.to_s}}}</span>
387 # A card that displays the code of a MEntity
390 autoinit
(mentity
, node
)
392 # AST node to display in this card
393 var node
: nullable ANode is writable
395 redef var id
= "code_{super}" is lazy
396 redef var title
= "Code"
398 redef fun rendering
do
399 addn
"<div id='{id}' class='card'>"
400 addn
" <div class='card-body'>"
407 addn
"<span class='text-muted'>{mentity.location}</span>"
413 private fun render_code
do
415 if node
== null then return
416 var hl
= new HtmlightVisitor
417 hl
.show_infobox
= false
418 hl
.highlight_node node
423 # A card that displays a graph
426 autoinit
(mentity
, graph
)
428 # Graph to display in this card
429 var graph
: InheritanceGraph is writable
431 redef var id
= "graph_{super}" is lazy
432 redef var title
= "Graph"
434 redef fun rendering
do
435 addn
"<div id='{id}' class='card'>"
436 addn
" <div class='card-body'>"
437 addn
" <div class='text-center'>"
438 addn graph
.graph
.to_svg
445 # Catalog related cards
447 # A card that displays Nit catalog related data
448 abstract class CardCatalog
452 # Catalog used to extract the data
453 var catalog
: Catalog is writable
456 # A card that displays statistics about a Nit catalog
457 class CardCatalogStats
460 redef var id
= "catalog_stats"
461 redef var title
= "Stats"
463 redef fun rendering
do
464 addn
"<div id='{id}' class='container-fluid'>"
465 for key
, value
in catalog
.catalog_stats
.to_map
do
466 addn
"<span class='text-muted small'>"
467 addn
" <strong>{value}</strong> <span>{key}</span> "
475 # A card that displays a list of tags
476 class CardCatalogTags
479 redef var id
= "catalog_tags"
480 redef var title
= "Tags"
482 # Sorter to sort tags alphabetically
483 var tags_sorter
= new CatalogTagsSorter is writable
485 redef fun rendering
do
486 var tags
= catalog
.tag2proj
.keys
.to_a
487 if tags
.is_empty
then return
488 tags_sorter
.sort
(tags
)
490 addn
"<h2 id='{id}'>Tags</h2>"
491 addn
"<div class='container-fluid'>"
493 addn
"<div class='col-xs-6 col-sm-3 col-md-2'>"
494 addn
" <span class='badge'>{catalog.tag2proj[tag].length}</span>"
495 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
503 # A card that displays a package from a Nit catalog
504 class CardCatalogPackage
507 autoinit
(catalog
, mentity
)
509 redef var id
= "package_{super}" is lazy
511 redef fun rendering
do
512 var mpackage
= self.mentity
513 if not mpackage
isa MPackage then return
516 <div id='{{{id}}}' class='card'>
517 <div class='card-left text-center'>{{{mpackage.html_icon.write_to_string}}}</div>
518 <div class='card-body' style='width: 75%'>
519 <h5 class='card-heading'>
520 {{{mentity.html_declaration.write_to_string}}}
522 for tag
in mpackage
.metadata
.tags
do
524 add
"<a href='tag_{tag.to_cmangle}.html' class='text-muted'>{tag}</a>"
525 if tag
!= mpackage
.metadata
.tags
.last
then addn
", "
530 var mdoc
= mentity
.mdoc_or_fallback
533 addn mdoc
.html_documentation
535 addn mdoc
.html_synopsis
539 addn
" <div class='card-right' style='width: 25%'>"
540 for maintainer
in mpackage
.metadata
.maintainers
do
541 addn maintainer
.to_html
544 var license
= mpackage
.metadata
.license
545 if license
!= null then
547 <span class='text-muted'>
548 <a href='http://opensource.org/licenses/{{{license}}}' class='text-muted'>
558 # A card that displays the metadata about a package in the Nit catalog
561 autoinit
(mentity
, metadata
, stats
, deps
, clients
)
563 # Package metadata to display
564 var metadata
: MPackageMetadata is writable
567 var stats
: MPackageStats is writable
569 # Package dependencies
570 var deps
: Array[MPackage] is writable
573 var clients
: Array[MPackage] is writable
575 redef var id
= "metadata_{super}" is lazy
576 redef var title
= "Metadata"
578 redef fun rendering
do
579 for maintainer
in metadata
.maintainers
do
582 {{{maintainer.to_html}}}
585 var license
= metadata
.license
586 if license
!= null then
588 <span class='text-muted'>
589 <a href='http://opensource.org/licenses/{{{license}}}'>{{{license}}}</a>
594 var homepage
= metadata
.homepage
595 var browse
= metadata
.browse
596 var issues
= metadata
.issues
597 if homepage
!= null or browse
!= null or issues
!= null then
600 <ul class='list-unstyled'>"""
601 if homepage
!= null then addn
"<li><a href='{homepage}'>Homepage</a></li>"
602 if browse
!= null then addn
"<li><a href='{browse}'>Source Code</a></li>"
603 if issues
!= null then addn
"<li><a href='{issues}'>Issues</a></li>"
607 var git
= metadata
.git
608 var last_date
= metadata
.last_date
609 var first_date
= metadata
.first_date
613 <ul class='list-unstyled'>
614 <li><a href='{{{git}}}'>{{{git}}}</a></li>
616 <span class='text-muted'><b>{{{stats.commits}}}</b> commits</span>
618 if last_date
!= null then
619 addn
"""<b class=text-muted>Last:</b> {{{last_date}}}<br>"""
621 if first_date
!= null then
622 addn
"""<b class=text-muted>First:</b> {{{first_date}}}"""
628 <ul class='list-unstyled'>
629 <li>{{{stats.documentation_score}}}% documented</li>
632 if metadata
.tags
.not_empty
then
634 for tag
in metadata
.tags
do
635 addn
" <a href='tag_{tag.to_cmangle}.html'>{tag}</a>"
636 if tag
!= metadata
.tags
.last
then add
", "
640 if deps
.not_empty
then
641 addn
"<h4>Dependencies</h4>"
644 if dep
!= deps
.last
then add
", "
648 if clients
.not_empty
then
649 addn
"<h4>Clients</h4>"
650 for client
in clients
do
652 if client
!= clients
.last
then add
", "
656 if metadata
.contributors
.not_empty
then
658 <h4>Contributors</h4>
659 <ul class='list-unstyled'>"""
660 for contrib
in metadata
.contributors
do
661 addn
"""<li>{{{contrib.to_html}}}</li>"""
668 <ul class='list-unstyled'>
669 <li>{{{stats.mmodules}}} modules</li>
670 <li>{{{stats.mclasses}}} classes</li>
671 <li>{{{stats.mmethods}}} methods</li>
672 <li>{{{stats.loc}}} loc</li>