# 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. # HTML templates used by Nitdoc to generate API documentation # Pages are assembled using `Template` module html_components import doc_base import html::bootstrap import json::static # A label with a text content. class DocHTMLLabel super BSLabel redef init do css_classes.clear css_classes.add "label" end # Init this label from css classes. init with_classes(classes: Array[String]) do init("label", "") css_classes.add_all classes end end ######################### # general layout elements ######################### # Something that can go in a section # Sections are automatically collected to populate the menu class TplSectionElt super Template # HTML anchor id var id: String # Title to display if any # if both `title` and `summary_title` are null then # the section will not appear in the summary var title: nullable Writable = null is writable # Subtitle to display if any var subtitle: nullable Writable = null is writable # Title that appear in the summary # if null use `title` instead var summary_title: nullable String = null is writable # CSS classes to apply on the section element var css_classes = new Array[String] # CSS classes to apply on the title heading element var title_classes = new Array[String] # Parent article/section if any var parent: nullable TplSectionElt = null init with_title(id: String, title: Writable) do init(id) self.title = title end # Level for HTML heading protected fun hlvl: Int do if parent == null then return 1 return parent.hlvl + 1 end # Elements contained by this section var children = new Array[TplSectionElt] # Add an element in this section fun add_child(child: TplSectionElt) do child.parent = self children.add child end # Is the section empty (no content at all) fun is_empty: Bool do return children.is_empty end # A HTML
element class TplSection super TplSectionElt redef fun rendering do addn "
" if title != null then var lvl = hlvl if lvl == 2 then title_classes.add "well well-sm" addn "" addn title.as(not null) addn "" end if subtitle != null then addn "
" addn subtitle.as(not null) addn "
" end for child in children do add child end addn "
" end end # A page article that can go in a section class TplArticle super TplSectionElt # Content for this article var content: nullable Writable = null is writable var source_link: nullable Writable = null is writable init with_content(id: String, title: Writable, content: Writable) do with_title(id, title) self.content = content end redef fun rendering do if is_empty then return addn "
" if source_link != null then add "" end if title != null then var lvl = hlvl if lvl == 2 then title_classes.add "well well-sm" add "" add title.as(not null) addn "" end if subtitle != null then add "
" add subtitle.as(not null) addn "
" end if content != null then add content.as(not null) end for child in children do add child end addn """
""" end redef fun is_empty: Bool do return title == null and subtitle == null and content == null and children.is_empty end end # A module / class / prop definition class TplDefinition super Template # Comment to display var comment: nullable Writable = null is writable # Namespace for this definition var namespace: nullable Writable = null is writable # Location link to display var location: nullable Writable = null is writable private fun render_info do addn "
" if namespace != null then if comment == null then add "no comment for " end add namespace.as(not null) end if location != null then add " " add location.as(not null) end addn "
" end private fun render_comment do if comment != null then add comment.as(not null) end redef fun rendering do addn "
" render_comment render_info addn "
" end end # Class definition class TplClassDefinition super TplDefinition var intros = new Array[TplListElt] var redefs = new Array[TplListElt] redef fun rendering do addn "
" render_comment render_info render_list("Introduces", intros) render_list("Redefines", redefs) addn "
" end private fun render_list(name: String, elts: Array[TplListElt]) do if elts.is_empty then return addn "
{name.html_escape}
" addn "" end end # Layout for Search page class TplSearchPage super TplSectionElt var modules = new Array[Writable] var classes = new Array[Writable] var props = new Array[Writable] redef fun rendering do var title = self.title if title != null then addn "

{title.to_s.html_escape}

" addn "
" addn "
" if not modules.is_empty then addn "
" addn "

Modules

" addn "
    " for m in modules do add "
  • " add m addn "
  • " end addn "
" addn "
" end if not classes.is_empty then addn "
" addn "

Classes

" addn "
    " for c in classes do add "
  • " add c addn "
  • " end addn "
" addn "
" end if not props.is_empty then addn "
" addn "

Properties

" addn "
    " for p in props do add "
  • " add p addn "
  • " end addn "
" addn "
" end addn "
" addn "
" end end ##################### # Basiv HTML elements ##################### # A html link class TplLink super Template # Link href var href: String is writable # The raw HTML content to display in the link var text: Writable is writable # The unescaped optional title. var title: nullable String = null is writable init with_title(href, text, title: String) do init(href, text) self.title = title end redef fun rendering do add "" add text add "" end end # A