X-Git-Url: http://nitlanguage.org diff --git a/src/doc/doc_templates.nit b/src/doc/doc_templates.nit index c4729a5..c23e880 100644 --- a/src/doc/doc_templates.nit +++ b/src/doc/doc_templates.nit @@ -23,7 +23,7 @@ import json::static 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 @@ -45,7 +45,7 @@ class TplPage var sections = new Array[TplSection] # Footer content if any - var footer: nullable Streamable = null is writable + var footer: nullable Writable = null is writable # JS scripts to append at the end of the body var scripts = new Array[TplScript] @@ -60,28 +60,28 @@ class TplPage var css = (self.shareurl / "css").html_escape var vendors = (self.shareurl / "vendors").html_escape - add "" - add "" - add " " - add " " - add " " - add " " - add " " - add " " - add " " - add " " - add " {title}" - add "" + 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 @@ -99,9 +99,9 @@ class TplPage private fun render_content do for section in sections do add section if footer != null then - add "" end end @@ -110,41 +110,41 @@ class TplPage var vendors = (self.shareurl / "vendors").html_escape var js = (self.shareurl / "js").html_escape - add "" - add "" - add "" - add "" + addn "" + 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 @@ -158,9 +158,9 @@ class TplTopMenu super Template # Brand link to display in first position of the top menu - private var brand: nullable Streamable = null is writable + private var brand: nullable Writable = null is writable # Elements of the topmenu - private var elts = new Array[Streamable] + private var elts = new Array[Writable] # The page url where the top menu is displayed. # @@ -174,7 +174,7 @@ class TplTopMenu end # Add a content between `
  • ` tags - fun add_item(content: Streamable, is_active: Bool) do + fun add_item(content: Writable, is_active: Bool) do var tpl = new Template tpl.add "" tpl.add content - tpl.add "
  • " + tpl.addn "" add_raw(tpl) end # Add a raw content to the menu - fun add_raw(content: Streamable) do + fun add_raw(content: Writable) do elts.add content end redef fun rendering do if brand == null and elts.is_empty then return - add "" end end @@ -233,9 +233,9 @@ class TplSidebar redef fun rendering do if boxes.is_empty then return order_boxes - add "" end end @@ -277,7 +277,7 @@ class TplSideBox # Content to display in the box # box will not be rendered if the content is null - var content: nullable Streamable = null is writable + var content: nullable Writable = null is writable # Is the box opened by default # otherwise, the user will have to clic on the title to display the content @@ -287,7 +287,7 @@ class TplSideBox self.id = title.to_cmangle end - init with_content(title: String, content: Streamable) do + init with_content(title: String, content: Writable) do init(title) self.content = content end @@ -296,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 @@ -332,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 @@ -352,7 +352,7 @@ class TplSummaryEntry super TplSummaryElt # Text to display - var text: Streamable + var text: Writable # Children of this entry # Will be displayed as a tree @@ -364,11 +364,11 @@ class TplSummaryEntry add "
  • " add text if not children.is_empty then - add "" end - add "
  • " + addn "" end end @@ -383,10 +383,10 @@ 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 = null is writable + var title: nullable Writable = null is writable # Subtitle to display if any - var subtitle: nullable Streamable = null is writable + var subtitle: nullable Writable = null is writable # Title that appear in the summary # if null use `title` instead @@ -401,7 +401,7 @@ class TplSectionElt # Parent article/section if any var parent: nullable TplSectionElt = null - init with_title(id: String, title: Streamable) do + init with_title(id: String, title: Writable) do init(id) self.title = title end @@ -444,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 @@ -469,10 +469,10 @@ class TplArticle super TplSectionElt # Content for this article - var content: nullable Streamable = null is writable - var source_link: nullable Streamable = null is writable + var content: nullable Writable = null is writable + var source_link: nullable Writable = null is writable - init with_content(id: String, title: Streamable, content: Streamable) do + init with_content(id: String, title: Writable, content: Writable) do with_title(id, title) self.content = content end @@ -488,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) @@ -512,7 +512,7 @@ class TplArticle for child in children do add child end - add """
    """ + addn """
    """ end redef fun is_empty: Bool do @@ -525,16 +525,16 @@ class TplDefinition super Template # Comment to display - var comment: nullable Streamable = null is writable + var comment: nullable Writable = null is writable # Namespace for this definition - var namespace: nullable Streamable = null is writable + var namespace: nullable Writable = null is writable # Location link to display - var location: nullable Streamable = null is writable + var location: nullable Writable = null is writable private fun render_info do - add "
    " + addn "
    " if namespace != null then if comment == null then add "no comment for " @@ -545,7 +545,7 @@ class TplDefinition add " " add location.as(not null) end - add "
    " + addn "
    " end private fun render_comment do @@ -553,10 +553,10 @@ class TplDefinition end redef fun rendering do - add "
    " + addn "
    " render_comment render_info - add "
    " + addn "
    " end end @@ -567,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.html_escape}
    " - add "" end end @@ -591,53 +589,53 @@ end class TplSearchPage super TplSectionElt - var modules = new Array[Streamable] - var classes = new Array[Streamable] - var props = new Array[Streamable] + 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 add "

    {title.to_s.html_escape}

    " - 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,10 +650,10 @@ class TplLink # Link href var href: String is writable - # Text to display in the link - var text: Streamable is writable + # The raw HTML content to display in the link + var text: Writable is writable - # Optional title + # The unescaped optional title. var title: nullable String = null is writable init with_title(href, text, title: String) do @@ -665,11 +663,11 @@ class TplLink redef fun rendering do add "" @@ -692,17 +690,15 @@ class TplList # Add content wrapped in a
  • element fun add_li(item: TplListItem) do elts.add item - init do end - init with_classes(classes: Array[String]) do self.css_classes = classes fun is_empty: Bool do return elts.is_empty redef fun rendering do if elts.is_empty then return - add "
      " + addn "
        " for elt in elts do add elt - add "
      " + addn "
    " end end @@ -721,23 +717,21 @@ 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_content(content: Writable) do append(content) - init with_classes(content: Streamable, classes: Array[String]) do + init with_classes(content: Writable, classes: Array[String]) do with_content(content) css_classes = classes end # Append `content` to the item # similar to `self.content.add` - fun append(content: Streamable) do self.content.add content + fun append(content: Writable) do self.content.add content redef fun rendering do add "
  • " add content - add "
  • " + addn "" end end @@ -755,9 +749,9 @@ class TplTab var css_classes = new Array[String] redef fun rendering do - add "
    " + addn "
    " for panel in panels do add panel - add "
    " + addn "
    " end end @@ -776,16 +770,16 @@ class TplTabPanel # The panel name. # # Displayed in the tab header or in the pointing link. - var name: Streamable + var name: Writable # Is the panel visible by default? var is_active = false is writable # Body of the panel - var content: nullable Streamable = null is writable + var content: nullable Writable = null is writable # Get a link pointing to this panel. - fun tpl_link_to: Streamable do + fun tpl_link_to: Writable do var lnk = new Template lnk.add "
    " lnk.add name @@ -796,9 +790,9 @@ class TplTabPanel redef fun rendering do add "
    " + addn "' id='{id}'>" if content != null then add content.as(not null) - add "
    " + addn "" end end @@ -807,12 +801,12 @@ class TplLabel super Template # Content of the label if any - var content: nullable Streamable = null is writable + var content: nullable Writable = null is writable # CSS classes of the element var css_classes = new Array[String] - init with_content(content: Streamable) do self.content = content + init with_content(content: Writable) do self.content = content init with_classes(classes: Array[String]) do self.css_classes = classes redef fun rendering do @@ -841,6 +835,16 @@ 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 @@ -850,9 +854,10 @@ class TagAttribute 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 @@ -862,7 +867,7 @@ class TplScript super Template var attrs = new Array[TagAttribute] - var content: nullable Streamable = null is writable + var content: nullable Writable = null is writable init do attrs.add(new TagAttribute("type", "text/javascript")) @@ -875,9 +880,9 @@ class TplScript redef fun rendering do add "" + addn ">" render_content - add "" + addn "" end end @@ -894,17 +899,17 @@ class TplPiwikScript if tracker_url.chars.last != '/' then tracker_url += "/" tracker_url = "://{tracker_url}".to_json - 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 "\})();" + 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