# This file is part of NIT ( http://www.nitlanguage.org ). # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Cards templates for the static documentation module static_cards import doc::commands::commands_graph import doc::commands::commands_catalog import doc::commands::commands_docdown import templates_html # A card that can be rendered to HTML # # Basically, these cards are templates with additionnal data and behavior. abstract class StaticCard super Template # Card title var title: String is writable # Card id var id: String is writable end # A list of cards class CardList super StaticCard # Cards contained in this list var cards = new Array[StaticCard] is writable redef fun rendering do addn "
" for card in cards do addn card end addn "
" end end # Doc elements # A card that display custom text data class CardText super StaticCard autoinit(content) # Custom content from options var content: nullable String is writable redef var id = "home" redef var title = "Home" redef fun rendering do var content = self.content if content == null then return addn "
" addn content addn "
" addn "
" end end # A heading section # # It displays an heading at a specific level from 1 to 6. class CardSection super StaticCard autoinit(level, title, subtitle) # Section heading level var level: Int is writable # Section subtitle var subtitle: nullable String is writable redef var id = title.to_cmangle is lazy redef fun rendering do addn "{title}" end end # A page header class CardPageHeader super CardSection autoinit(title, subtitle) redef var level = 2 redef fun rendering do addn "" end end # A card that displays a summary of a list of cards class CardSummary super CardList autoinit(no_title) redef var id = "summary" redef var title = "Summary" # Show the summary title var no_title: Bool = false is optional, writable redef fun rendering do if not no_title then addn "

Summary

" end addn "
" addn " " addn "
" end end # A card that displays the summary of a Markdown document class CardMdSummary super CardMDoc autoinit(md_processor, headlines) # Markdown processor used to extract and render the content var md_processor: MarkdownProcessor is writable # Headlines found in the document var headlines: ArrayMap[String, HeadLine] is writable redef var id = "summary" redef var title = "Summary" redef fun rendering do addn "

Summary

" addn "
" addn " " addn "
" end end # MEntity related cards # A card about a mentity # # It displays the documentation about the model entity. class CardMEntity super StaticCard autoinit(mentity, full_doc) # MEntity displayed in this card var mentity: MEntity is writable # Render the mentity full documentation? var full_doc = false is optional, writable redef var id = mentity.html_id is lazy redef var title = mentity.html_name is lazy redef fun rendering do addn """
{{{mentity.html_icon.write_to_string}}}
{{{mentity.html_declaration.write_to_string}}}

{{{mentity.html_namespace.write_to_string}}}

""" var mdoc = mentity.mdoc_or_fallback if mdoc != null then if full_doc then addn mdoc.html_documentation else addn mdoc.html_synopsis end end addn """
""" end end # A card that displays the content of a MDoc class CardMDoc super CardMEntity autoinit(mentity, mdoc, full_doc) # MDoc to display in this card var mdoc: nullable MDoc is writable redef fun rendering do var mdoc = self.mdoc if mdoc == null then return addn "
" addn "
" addn mdoc.html_documentation addn "
" addn "
" end end # A card about the inheritance of a MEntity class CardInheritance super CardMEntity # Ancestors list var ancestors: nullable Array[MEntity] is writable # Parents list var parents: nullable Array[MEntity] is writable # Children list var children: nullable Array[MEntity] is writable # Descendants list var descendants: nullable Array[MEntity] is writable redef var id = "inh_{super}" is lazy redef var title = "Inheritance" is lazy redef fun rendering do var ancestors = self.ancestors var descendants = self.descendants if ancestors == null and parents == null and children == null and descendants == null then return addn "
" addn "
" if ancestors != null and ancestors.length <= 10 then render_list("Ancestors", ancestors) else render_list("Parents", parents) end if descendants != null and descendants.length <= 10 then render_list("Descendants", descendants) else render_list("Children", children) end addn "
" addn "
" end private fun render_list(title: String, mentities: nullable Array[MEntity]) do if mentities == null or mentities.is_empty then return addn "

{title}

" addn "" end private fun html_list_item(mentity: MEntity): ListItem do var tpl = new Template tpl.add mentity.html_namespace var comment = mentity.mdoc_or_fallback if comment != null then tpl.add ": " tpl.add comment.html_synopsis end return new ListItem(tpl) end end # A card about the linearization of a MEntity class CardLinearizationList super CardMEntity # Linearization cards contained in this list var cards = new Array[CardLinearizationDef] is writable redef var id = "lin_{super}" is lazy redef var title = "Linearization" is lazy redef fun rendering do if cards.is_empty then return addn "
" for card in cards do addn card if card == cards.last then break addn "

" addn " " addn "

" end addn "
" end end # A card about a definition in a linearization list class CardLinearizationDef super CardCode # Is this card displayed by default? var is_active: Bool = false is optional, writable # Link to external code repository # # Used if `node` is null var url: nullable String = null is optional, writable redef var id = "def_{super}" is lazy redef var title = mentity.full_name is lazy redef fun rendering do var url = self.url var cin = if is_active then "in" else "" var active = if is_active then "active" else "" addn """
{{{mentity.html_icon.write_to_string}}} {{{mentity.html_namespace.write_to_string}}}""" if node != null then addn """
""" else if url != null then addn """ """ var mdoc = mentity.mdoc if mdoc != null then addn "

" addn mdoc.html_documentation end end addn "
" if node != null then addn """
"""
			render_code
			addn """
{{{mentity.location.to_s}}}
""" end addn """
""" end end # A card that displays the code of a MEntity class CardCode super CardMEntity autoinit(mentity, node) # AST node to display in this card var node: nullable ANode is writable redef var id = "code_{super}" is lazy redef var title = "Code" redef fun rendering do addn "
" addn "
" if node != null then addn "
"
			render_code
			addn "
" end addn "{mentity.location}" addn "
" addn "
" end private fun render_code do var node = self.node if node == null then return var hl = new HtmlightVisitor hl.show_infobox = false hl.highlight_node node addn hl.html end end # A card that displays a graph class CardGraph super CardMEntity autoinit(mentity, graph) # Graph to display in this card var graph: InheritanceGraph is writable redef var id = "graph_{super}" is lazy redef var title = "Graph" redef fun rendering do addn "
" addn "
" addn "
" addn graph.graph.to_svg addn "
" addn "
" addn "
" end end # Catalog related cards # A card that displays Nit catalog related data abstract class CardCatalog super StaticCard autoinit(catalog) # Catalog used to extract the data var catalog: Catalog is writable end # A card that displays statistics about a Nit catalog class CardCatalogStats super CardCatalog redef var id = "catalog_stats" redef var title = "Stats" redef fun rendering do addn "
" for key, value in catalog.catalog_stats.to_map do addn "" addn " {value} {key} " addn "" end addn "
" addn "
" end end # A card that displays a list of tags class CardCatalogTags super CardCatalog redef var id = "catalog_tags" redef var title = "Tags" # Sorter to sort tags alphabetically var tags_sorter = new CatalogTagsSorter is writable redef fun rendering do var tags = catalog.tag2proj.keys.to_a if tags.is_empty then return tags_sorter.sort(tags) addn "

Tags

" addn "
" for tag in tags do addn "
" addn " {catalog.tag2proj[tag].length}" addn " {tag}" addn "
" end addn "
" addn "
" end end # A card that displays a package from a Nit catalog class CardCatalogPackage super CardCatalog super CardMEntity autoinit(catalog, mentity) redef var id = "package_{super}" is lazy redef fun rendering do var mpackage = self.mentity if not mpackage isa MPackage then return addn """
{{{mpackage.html_icon.write_to_string}}}
{{{mentity.html_declaration.write_to_string}}}  """ for tag in mpackage.metadata.tags do add "" add "{tag}" if tag != mpackage.metadata.tags.last then addn ", " add "" end addn """
""" var mdoc = mentity.mdoc_or_fallback if mdoc != null then if full_doc then addn mdoc.html_documentation else addn mdoc.html_synopsis end end addn "
" addn "
" for maintainer in mpackage.metadata.maintainers do addn maintainer.to_html end addn "
" var license = mpackage.metadata.license if license != null then addn """ {{{license}}} """ end addn "
" addn "
" end end # A card that displays the metadata about a package in the Nit catalog class CardMetadata super CardMEntity autoinit(mentity, metadata, stats, deps, clients) # Package metadata to display var metadata: MPackageMetadata is writable # Package stats var stats: MPackageStats is writable # Package dependencies var deps: Array[MPackage] is writable # Package clients var clients: Array[MPackage] is writable redef var id = "metadata_{super}" is lazy redef var title = "Metadata" redef fun rendering do for maintainer in metadata.maintainers do addn """

{{{maintainer.to_html}}}

""" end var license = metadata.license if license != null then addn """ {{{license}}} license """ end var homepage = metadata.homepage var browse = metadata.browse var issues = metadata.issues if homepage != null or browse != null or issues != null then addn """

Links

" end var git = metadata.git var last_date = metadata.last_date var first_date = metadata.first_date if git != null then addn """

Git

{{{stats.commits}}} commits
""" if last_date != null then addn """Last: {{{last_date}}}
""" end if first_date != null then addn """First: {{{first_date}}}""" end end addn """

Quality

""" if metadata.tags.not_empty then addn "

Tags

" for tag in metadata.tags do addn " {tag}" if tag != metadata.tags.last then add ", " end end if deps.not_empty then addn "

Dependencies

" for dep in deps do add dep.html_link if dep != deps.last then add ", " end end if clients.not_empty then addn "

Clients

" for client in clients do add client.html_link if client != clients.last then add ", " end end if metadata.contributors.not_empty then addn """

Contributors

" end addn """

Stats

""" end end