X-Git-Url: http://nitlanguage.org diff --git a/src/doc/doc_templates.nit b/src/doc/doc_templates.nit index e30298f9..497c4cd 100644 --- a/src/doc/doc_templates.nit +++ b/src/doc/doc_templates.nit @@ -17,12 +17,13 @@ module doc_templates import template +import json::static # A documentation page class TplPage super Template - # Page title in HTML header + # The unescaped page title to put in the HTML header. var title: String is writable, noinit # Page url @@ -49,8 +50,6 @@ class TplPage # JS scripts to append at the end of the body var scripts = new Array[TplScript] - init do end - # Add a section to this page fun add_section(section: TplSection) do sections.add section @@ -58,28 +57,31 @@ class TplPage # Render the html header private fun render_head do - add "" - add "" - add " " - add " " - add " " - add " " - add " " - add " " - add " " - add " " - add " {title}" - add "" + var css = (self.shareurl / "css").html_escape + var vendors = (self.shareurl / "vendors").html_escape + + addn "" + addn "" + addn " " + addn " " + addn " " + addn " " + addn " " + addn " " + addn " " + addn " " + addn " {title.html_escape}" + addn "" add "" + addn ">" end # Render the topmenu template private fun render_topmenu do - add "
" + addn "
" add topmenu - add "
" + addn "
" end # Render the sidebar @@ -97,49 +99,52 @@ class TplPage private fun render_content do for section in sections do add section if footer != null then - add "" end end # Render JS scripts private fun render_footer do - add "" - add "" - add "" - add "" + addn "" + addn "" + addn "" for script in scripts do add script - add """""" - add "" - add "" + addn "" + addn "" end # Render the whole page redef fun rendering do render_head - add "
" + addn "
" render_topmenu - add "
" + addn "
" if sidebar != null then - add "
" + addn "
" render_sidebar - add "
" - add "
" + addn "
" + addn "
" render_content - add "
" + addn "
" else - add "
" + addn "
" render_content - add "
" + addn "
" end - add "
" - add "
" + addn "
" + addn "
" render_footer end end @@ -162,10 +167,6 @@ class TplTopMenu # Used to select the active link. private var current_url: String - init(current_url: String) do - self.current_url = current_url - end - # Add a new link to the menu. fun add_link(content: TplLink) do var is_active = content.href == current_url @@ -181,7 +182,7 @@ class TplTopMenu end tpl.add ">" tpl.add content - tpl.add "" + tpl.addn "" add_raw(tpl) end @@ -192,27 +193,27 @@ class TplTopMenu redef fun rendering do if brand == null and elts.is_empty then return - add "" end end @@ -232,15 +233,17 @@ class TplSidebar redef fun rendering do if boxes.is_empty then return order_boxes - add "" end end # Comparator used to sort boxes by order private class OrderComparator - super Comparator[TplSidebarElt] + super Comparator + + redef type COMPARED: TplSidebarElt redef fun compare(a, b) do if a.order < b.order then return -1 @@ -270,18 +273,17 @@ class TplSideBox # Box HTML id # equals to `title.to_cmangle` by default # Used for collapsing - var id: String + var id: String is noinit # Content to display in the box # box will not be rendered if the content is null - var content: nullable Streamable writable + var content: nullable Streamable = null is writable # Is the box opened by default # otherwise, the user will have to clic on the title to display the content - var is_open writable = false + var is_open = false is writable - init(title: String) do - self.title = title + init do self.id = title.to_cmangle end @@ -294,16 +296,16 @@ class TplSideBox if content == null then return var open = "" if is_open then open = "in" - add "
" - add "
" + addn "
" + addn "
" add " " add title - add " " - add "
" - add "
" + addn " " + addn "
" + addn "
" add content.as(not null) - add "
" - add "
" + addn "
" + addn "
" end end @@ -330,18 +332,18 @@ class TplSummary redef fun rendering do if children.is_empty then return - add "
" - add "
" + addn "
" + addn "
" add " " add "Summary" - add " " - add "
" - add "
" - add "
" + addn "
" + addn " " - add "
" - add "
" + addn " " + addn "
" + addn "
" end end @@ -356,19 +358,17 @@ class TplSummaryEntry # Will be displayed as a tree var children = new Array[TplSummaryElt] - init(text: Streamable) do self.text = text - redef fun add_child(child) do children.add child redef fun rendering do add "
  • " add text if not children.is_empty then - add "" end - add "
  • " + addn "" end end @@ -383,14 +383,14 @@ class TplSectionElt # 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 Streamable writable + var title: nullable Streamable = null is writable # Subtitle to display if any - var subtitle: nullable Streamable writable + var subtitle: nullable Streamable = null is writable # Title that appear in the summary # if null use `title` instead - var summary_title: nullable String writable + var summary_title: nullable String = null is writable # CSS classes to apply on the section element var css_classes = new Array[String] @@ -399,9 +399,7 @@ class TplSectionElt var title_classes = new Array[String] # Parent article/section if any - var parent: nullable TplSectionElt - - init(id: String) do self.id = id + var parent: nullable TplSectionElt = null init with_title(id: String, title: Streamable) do init(id) @@ -446,23 +444,23 @@ class TplSection super TplSectionElt redef fun rendering do - add "
    " + addn "
    " if title != null then var lvl = hlvl if lvl == 2 then title_classes.add "well well-sm" - add "" - add title.as(not null) - add "" + addn "" + addn title.as(not null) + addn "" end if subtitle != null then - add "
    " - add subtitle.as(not null) - add "
    " + addn "
    " + addn subtitle.as(not null) + addn "
    " end for child in children do add child end - add "
    " + addn "
    " end end @@ -471,8 +469,8 @@ class TplArticle super TplSectionElt # Content for this article - var content: nullable Streamable writable = null - var source_link: nullable Streamable writable = null + var content: nullable Streamable = null is writable + var source_link: nullable Streamable = null is writable init with_content(id: String, title: Streamable, content: Streamable) do with_title(id, title) @@ -490,23 +488,23 @@ class TplArticle redef fun rendering do if is_empty then return - add "
    " + addn "
    " if source_link != null then add "" + addn "" end if title != null then var lvl = hlvl if lvl == 2 then title_classes.add "well well-sm" add "" add title.as(not null) - add "" + addn "" end if subtitle != null then add "
    " add subtitle.as(not null) - add "
    " + addn "" end if content != null then add content.as(not null) @@ -514,7 +512,7 @@ class TplArticle for child in children do add child end - add """
    """ + addn """
    """ end redef fun is_empty: Bool do @@ -536,7 +534,7 @@ class TplDefinition var location: nullable Streamable = null is writable private fun render_info do - add "
    " + addn "
    " if namespace != null then if comment == null then add "no comment for " @@ -547,7 +545,7 @@ class TplDefinition add " " add location.as(not null) end - add "
    " + addn "
    " end private fun render_comment do @@ -555,10 +553,10 @@ class TplDefinition end redef fun rendering do - add "
    " + addn "
    " render_comment render_info - add "
    " + addn "
    " end end @@ -569,23 +567,21 @@ class TplClassDefinition var intros = new Array[TplListElt] var redefs = new Array[TplListElt] - init do end - redef fun rendering do - add "
    " + addn "
    " render_comment render_info render_list("Introduces", intros) render_list("Redefines", redefs) - add "
    " + addn "
    " end private fun render_list(name: String, elts: Array[TplListElt]) do if elts.is_empty then return - add "
    {name}
    " - add "" end end @@ -599,47 +595,47 @@ class TplSearchPage redef fun rendering do var title = self.title - if title != null then add "

    {title}

    " - add "
    " - add "
    " + if title != null then addn "

    {title.to_s.html_escape}

    " + addn "
    " + addn "
    " if not modules.is_empty then - add "
    " - add "

    Modules

    " - add "
      " + addn "
      " + addn "

      Modules

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

    Classes

    " - add "
      " + addn "
      " + addn "

      Classes

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

    Properties

    " - add "
      " + addn "
      " + addn "

      Properties

      " + addn "
        " for p in props do add "
      • " add p - add "
      • " + addn "" end - add "
      " - add "
      " + addn "
    " + addn "
    " end - add "
    " - add "
    " + addn "
    " + addn "
    " end end @@ -652,18 +648,13 @@ class TplLink super Template # Link href - var href: String writable + var href: String is writable # Text to display in the link - var text: Streamable writable + var text: Streamable is writable # Optional title - var title: nullable String writable - - init(href, text: String) do - self.href = href - self.text = text - end + var title: nullable String = null is writable init with_title(href, text, title: String) do init(href, text) @@ -697,9 +688,7 @@ class TplList var css_classes = new Array[String] # Add content wrapped in a
  • element - fun add_li(content: Streamable) do elts.add new TplListItem.with_content(content) - - init do end + fun add_li(item: TplListItem) do elts.add item init with_classes(classes: Array[String]) do self.css_classes = classes @@ -707,9 +696,9 @@ class TplList redef fun rendering do if elts.is_empty then return - add "" end end @@ -728,8 +717,6 @@ class TplListItem # CSS classes of the
  • element var css_classes = new Array[String] - init do end - init with_content(content: Streamable) do append(content) init with_classes(content: Streamable, classes: Array[String]) do @@ -744,7 +731,68 @@ class TplListItem redef fun rendering do add "
  • " add content - add "
  • " + addn "" + end +end + +# A Bootstrap tab component that contains `TplTabPanel`. +class TplTab + super Template + + # Panels contained in the tab. + var panels = new Array[TplTabPanel] + + # Add a new panel. + fun add_panel(panel: TplTabPanel) do panels.add panel + + # CSS classes of the tab component. + var css_classes = new Array[String] + + redef fun rendering do + addn "
    " + for panel in panels do add panel + addn "
    " + end +end + +# A panel that goes in a `TplTab`. +class TplTabPanel + super Template + + # CSS classes of the pane element. + var css_classes = new Array[String] + + # The panel id. + # + # Used to show/hide panel. + var id: String is noinit + + # The panel name. + # + # Displayed in the tab header or in the pointing link. + var name: Streamable + + # Is the panel visible by default? + var is_active = false is writable + + # Body of the panel + var content: nullable Streamable = null is writable + + # Get a link pointing to this panel. + fun tpl_link_to: Streamable do + var lnk = new Template + lnk.add "" + lnk.add name + lnk.add "" + return lnk + end + + redef fun rendering do + add "
    " + if content != null then add content.as(not null) + addn "
    " end end @@ -787,23 +835,29 @@ end # A HTML tag attribute # `` +# +# ~~~nit +# var attr: TagAttribute +# +# attr = new TagAttribute("foo", null) +# assert attr.write_to_string == " foo=\"\"" +# +# attr = new TagAttribute("foo", "bar<>") +# assert attr.write_to_string == " foo=\"bar<>\"" +# ~~~ class TagAttribute super Template var name: String var value: nullable String - init(name: String, value: nullable String) do - self.name = name - self.value = value - end - redef fun rendering do var value = self.value if value == null then - add(" {name}") + # SEE: http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes + add " {name.html_escape}=\"\"" else - add(" {name}=\"{value}\"") + add " {name.html_escape}=\"{value.html_escape}\"" end end end @@ -826,9 +880,9 @@ class TplScript redef fun rendering do add "" + addn ">" render_content - add "" + addn "" end end @@ -839,24 +893,23 @@ class TplPiwikScript var tracker_url: String var site_id: String - init(tracker_url, site_id: String) do - super - self.tracker_url = tracker_url - self.site_id = site_id - end - redef fun render_content do - add "" - add "var _paq = _paq || [];" - add " _paq.push([\"trackPageView\"]);" - add " _paq.push([\"enableLinkTracking\"]);" - add "(function() \{" - add " var u=((\"https:\" == document.location.protocol) ? \"https\" : \"http\") + \"://{tracker_url}\";" - add " _paq.push([\"setTrackerUrl\", u+\"piwik.php\"]);" - add " _paq.push([\"setSiteId\", \"{site_id}\"]);" - add " var d=document, g=d.createElement(\"script\"), s=d.getElementsByTagName(\"script\")[0]; g.type=\"text/javascript\";" - add " g.defer=true; g.async=true; g.src=u+\"piwik.js\"; s.parentNode.insertBefore(g,s);" - add "\})();" + var site_id = self.site_id.to_json + var tracker_url = self.tracker_url.trim + if tracker_url.chars.last != '/' then tracker_url += "/" + tracker_url = "://{tracker_url}".to_json + + addn "" + addn "var _paq = _paq || [];" + addn " _paq.push([\"trackPageView\"]);" + addn " _paq.push([\"enableLinkTracking\"]);" + addn "(function() \{" + addn " var u=((\"https:\" == document.location.protocol) ? \"https\" : \"http\") + {tracker_url};" + addn " _paq.push([\"setTrackerUrl\", u+\"piwik.php\"]);" + addn " _paq.push([\"setSiteId\", {site_id}]);" + addn " var d=document, g=d.createElement(\"script\"), s=d.getElementsByTagName(\"script\")[0]; g.type=\"text/javascript\";" + addn " g.defer=true; g.async=true; g.src=u+\"piwik.js\"; s.parentNode.insertBefore(g,s);" + addn "\})();" end end