lib/standard/stream: Renamed streams for more explicit denomination
[nit.git] / src / doc / doc_templates.nit
index 9f4e3fb..c23e880 100644 (file)
@@ -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 "<!DOCTYPE html>"
-               add "<head>"
-               add " <meta charset='utf-8'/>"
-               add " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
-               add " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
-               add " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
-               add " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
-               add " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
-               add " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
-               add " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
-               add " <title>{title}</title>"
-               add "</head>"
+               addn "<!DOCTYPE html>"
+               addn "<head>"
+               addn " <meta charset='utf-8'/>"
+               addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
+               addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
+               addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
+               addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
+               addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
+               addn " <title>{title.html_escape}</title>"
+               addn "</head>"
                add "<body"
                for attr in body_attrs do add attr
-               add ">"
+               addn ">"
        end
 
        # Render the topmenu template
        private fun render_topmenu do
-               add " <div class='row'>"
+               addn " <div class='row'>"
                add topmenu
-               add " </div>"
+               addn " </div>"
        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 "<div class='well footer'>"
+                       addn "<div class='well footer'>"
                        add footer.as(not null)
-                       add "</div>"
+                       addn "</div>"
                end
        end
 
@@ -110,41 +110,41 @@ class TplPage
                var vendors = (self.shareurl / "vendors").html_escape
                var js = (self.shareurl / "js").html_escape
 
-               add "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
-               add "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
-               add "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
-               add "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
+               addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
+               addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
+               addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
+               addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
                for script in scripts do add script
-               add """<script>
+               addn """<script>
                        $(function () {
                                $("[data-toggle='tooltip']").tooltip();
                                $("[data-toggle='popover']").popover();
                        });
                </script>"""
-               add "</body>"
-               add "</html>"
+               addn "</body>"
+               addn "</html>"
        end
 
        # Render the whole page
        redef fun rendering do
                render_head
-               add "<div class='container-fluid'>"
+               addn "<div class='container-fluid'>"
                render_topmenu
-               add " <div class='row' id='content'>"
+               addn " <div class='row' id='content'>"
                if sidebar != null then
-                       add "<div class='col col-xs-3 col-lg-2'>"
+                       addn "<div class='col col-xs-3 col-lg-2'>"
                        render_sidebar
-                       add "</div>"
-                       add "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
+                       addn "</div>"
+                       addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
                        render_content
-                       add "</div>"
+                       addn "</div>"
                else
-                       add "<div class='col col-xs-12'>"
+                       addn "<div class='col col-xs-12'>"
                        render_content
-                       add "</div>"
+                       addn "</div>"
                end
-               add " </div>"
-               add "</div>"
+               addn " </div>"
+               addn "</div>"
                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 `<li>` 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 "<li"
                if is_active then
@@ -182,38 +182,38 @@ class TplTopMenu
                end
                tpl.add ">"
                tpl.add content
-               tpl.add "</li>"
+               tpl.addn "</li>"
                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 "<nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>"
-               add " <div class='container-fluid'>"
-               add "  <div class='navbar-header'>"
+               addn "<nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>"
+               addn " <div class='container-fluid'>"
+               addn "  <div class='navbar-header'>"
                add "   <button type='button' class='navbar-toggle' "
-               add "       data-toggle='collapse' data-target='#topmenu-collapse'>"
-               add "    <span class='sr-only'>Toggle menu</span>"
-               add "    <span class='icon-bar'></span>"
-               add "    <span class='icon-bar'></span>"
-               add "    <span class='icon-bar'></span>"
-               add "   </button>"
+               addn "       data-toggle='collapse' data-target='#topmenu-collapse'>"
+               addn "    <span class='sr-only'>Toggle menu</span>"
+               addn "    <span class='icon-bar'></span>"
+               addn "    <span class='icon-bar'></span>"
+               addn "    <span class='icon-bar'></span>"
+               addn "   </button>"
                if brand != null then add brand.as(not null)
-               add "  </div>"
-               add "  <div class='collapse navbar-collapse' id='topmenu-collapse'>"
+               addn "  </div>"
+               addn "  <div class='collapse navbar-collapse' id='topmenu-collapse'>"
                if not elts.is_empty then
-                       add "<ul class='nav navbar-nav'>"
+                       addn "<ul class='nav navbar-nav'>"
                        for elt in elts do add elt
-                       add "</ul>"
+                       addn "</ul>"
                end
-               add "  </div>"
-               add " </div>"
-               add "</nav>"
+               addn "  </div>"
+               addn " </div>"
+               addn "</nav>"
        end
 end
 
@@ -233,9 +233,9 @@ class TplSidebar
        redef fun rendering do
                if boxes.is_empty then return
                order_boxes
-               add "<div id='sidebar'>"
+               addn "<div id='sidebar'>"
                for box in boxes do add box
-               add "</div>"
+               addn "</div>"
        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 "<div class='panel'>"
-               add " <div class='panel-heading'>"
+               addn "<div class='panel'>"
+               addn " <div class='panel-heading'>"
                add "  <a data-toggle='collapse' data-parent='#sidebar' data-target='#box_{id}' href='#'>"
                add title
-               add "  </a>"
-               add " </div>"
-               add " <div id='box_{id}' class='panel-body collapse {open}'>"
+               addn "  </a>"
+               addn " </div>"
+               addn " <div id='box_{id}' class='panel-body collapse {open}'>"
                add content.as(not null)
-               add " </div>"
-               add "</div>"
+               addn " </div>"
+               addn "</div>"
        end
 end
 
@@ -332,18 +332,18 @@ class TplSummary
 
        redef fun rendering do
                if children.is_empty then return
-               add "<div class='panel'>"
-               add " <div class='panel-heading'>"
+               addn "<div class='panel'>"
+               addn " <div class='panel-heading'>"
                add "  <a data-toggle='collapse' data-parent='#sidebar' data-target='#box-sum' href='#'>"
                add "Summary"
-               add "  </a>"
-               add " </div>"
-               add " <div id='box-sum' class='summary collapse in'>"
-               add " <ul class='nav'>"
+               addn "  </a>"
+               addn " </div>"
+               addn " <div id='box-sum' class='summary collapse in'>"
+               addn " <ul class='nav'>"
                for entry in children do add entry
-               add " </ul>"
-               add " </div>"
-               add "</div>"
+               addn " </ul>"
+               addn " </div>"
+               addn "</div>"
        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 "<li>"
                add text
                if not children.is_empty then
-                       add "<ul class='nav'>"
+                       addn "\n<ul class='nav'>"
                        for entry in children do add entry
-                       add "</ul>"
+                       addn "</ul>"
                end
-               add "</li>"
+               addn  "</li>"
        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 "<section id='{id}' class='{css_classes.join(" ")}'>"
+               addn "<section id='{id}' class='{css_classes.join(" ")}'>"
                if title != null then
                        var lvl = hlvl
                        if lvl == 2 then title_classes.add "well well-sm"
-                       add "<h{lvl} class='{title_classes.join(" ")}'>"
-                       add title.as(not null)
-                       add "</h{lvl}>"
+                       addn "<h{lvl} class='{title_classes.join(" ")}'>"
+                       addn title.as(not null)
+                       addn "</h{lvl}>"
                end
                if subtitle != null then
-                       add "<div class='info subtitle'>"
-                       add subtitle.as(not null)
-                       add "</div>"
+                       addn "<div class='info subtitle'>"
+                       addn subtitle.as(not null)
+                       addn "</div>"
                end
                for child in children do
                        add child
                end
-               add "</section>"
+               addn "</section>"
        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 "<article id='{id}' class='{css_classes.join(" ")}'>"
+               addn "<article id='{id}' class='{css_classes.join(" ")}'>"
                if source_link != null then
                        add "<div class='source-link'>"
                        add source_link.as(not null)
-                       add "</div>"
+                       addn "</div>"
                end
                if title != null then
                        var lvl = hlvl
                        if lvl == 2 then title_classes.add "well well-sm"
                        add "<h{lvl} class='{title_classes.join(" ")}'>"
                        add title.as(not null)
-                       add "</h{lvl}>"
+                       addn "</h{lvl}>"
                end
                if subtitle != null then
                        add "<div class='info subtitle'>"
                        add subtitle.as(not null)
-                       add "</div>"
+                       addn "</div>"
                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 """</article>"""
+               addn """</article>"""
        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 "<div class='info text-right'>"
+               addn "<div class='info text-right'>"
                if namespace != null then
                        if comment == null then
                                add "<span class=\"noComment\">no comment for </span>"
@@ -545,7 +545,7 @@ class TplDefinition
                        add " "
                        add location.as(not null)
                end
-               add "</div>"
+               addn "</div>"
        end
 
        private fun render_comment do
@@ -553,10 +553,10 @@ class TplDefinition
        end
 
        redef fun rendering do
-               add "<div class='definition'>"
+               addn "<div class='definition'>"
                render_comment
                render_info
-               add "</div>"
+               addn "</div>"
        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 "<div class='definition'>"
+               addn "<div class='definition'>"
                render_comment
                render_info
                render_list("Introduces", intros)
                render_list("Redefines", redefs)
-               add "</div>"
+               addn "</div>"
        end
 
        private fun render_list(name: String, elts: Array[TplListElt]) do
                if elts.is_empty then return
-               add "<h5>{name}</h5>"
-               add "<ul class='list-unstyled list-definition'>"
+               addn "<h5>{name.html_escape}</h5>"
+               addn "<ul class='list-unstyled list-definition'>"
                for elt in elts do add elt
-               add "</ul>"
+               addn "</ul>"
        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 "<h1>{title}</h1>"
-               add "<div class='container-fluid'>"
-               add " <div class='row'>"
+               if title != null then addn "<h1>{title.to_s.html_escape}</h1>"
+               addn "<div class='container-fluid'>"
+               addn " <div class='row'>"
                if not modules.is_empty then
-                       add "<div class='col-xs-4'>"
-                       add "<h3>Modules</h3>"
-                       add "<ul>"
+                       addn "<div class='col-xs-4'>"
+                       addn "<h3>Modules</h3>"
+                       addn "<ul>"
                        for m in modules do
                                add "<li>"
                                add m
-                               add "</li>"
+                               addn "</li>"
                        end
-                       add "</ul>"
-                       add "</div>"
+                       addn "</ul>"
+                       addn "</div>"
                end
                if not classes.is_empty then
-                       add "<div class='col-xs-4'>"
-                       add "<h3>Classes</h3>"
-                       add "<ul>"
+                       addn "<div class='col-xs-4'>"
+                       addn "<h3>Classes</h3>"
+                       addn "<ul>"
                        for c in classes do
                                add "<li>"
                                add c
-                               add "</li>"
+                               addn "</li>"
                        end
-                       add "</ul>"
-                       add "</div>"
+                       addn "</ul>"
+                       addn "</div>"
                end
                if not props.is_empty then
-                       add "<div class='col-xs-4'>"
-                       add "<h3>Properties</h3>"
-                       add "<ul>"
+                       addn "<div class='col-xs-4'>"
+                       addn "<h3>Properties</h3>"
+                       addn "<ul>"
                        for p in props do
                                add "<li>"
                                add p
-                               add "</li>"
+                               addn "</li>"
                        end
-                       add "</ul>"
-                       add "</div>"
+                       addn "</ul>"
+                       addn "</div>"
                end
-               add " </div>"
-               add "</div>"
+               addn " </div>"
+               addn "</div>"
        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 "<a href=\""
-               add href
+               add href.html_escape
                add "\""
                if title != null then
                        add " title=\""
-                       add title.as(not null)
+                       add title.as(not null).html_escape
                        add "\""
                end
                add ">"
@@ -692,17 +690,15 @@ class TplList
        # Add content wrapped in a <li> 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 "<ul class='{css_classes.join(" ")}'>"
+               addn "<ul class='{css_classes.join(" ")}'>"
                for elt in elts do add elt
-               add "</ul>"
+               addn "</ul>"
        end
 end
 
@@ -721,23 +717,21 @@ class TplListItem
        # CSS classes of the <li> 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 "<li class='{css_classes.join(" ")}'>"
                add content
-               add "</li>"
+               addn "</li>"
        end
 end
 
@@ -755,9 +749,9 @@ class TplTab
        var css_classes = new Array[String]
 
        redef fun rendering do
-               add "<div class='tab-content'>"
+               addn "<div class='tab-content'>"
                for panel in panels do add panel
-               add "</div>"
+               addn "</div>"
        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 "<a data-target='#{id}' data-toggle='pill'>"
                lnk.add name
@@ -796,9 +790,9 @@ class TplTabPanel
        redef fun rendering do
                add "<div class='tab-pane {css_classes.join(" ")}"
                if is_active then add "active"
-               add "' id='{id}'>"
+               addn "' id='{id}'>"
                if content != null then add content.as(not null)
-               add "</div>"
+               addn "</div>"
        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 <span> 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
 #  `<tag attr="value">`
+#
+# ~~~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&lt;&gt;\""
+# ~~~
 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 "<script"
                for attr in attrs do add attr
-               add ">"
+               addn ">"
                render_content
-               add "</script>"
+               addn "</script>"
        end
 end
 
@@ -894,17 +899,17 @@ class TplPiwikScript
                if tracker_url.chars.last != '/' then tracker_url += "/"
                tracker_url = "://{tracker_url}".to_json
 
-               add "<!-- Piwik -->"
-               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 "<!-- Piwik -->"
+               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