src/doc: migrate sidebar to new templates
[nit.git] / src / doc / doc_phases / doc_html.nit
index f19922f..051fdd8 100644 (file)
@@ -170,9 +170,9 @@ redef class DocPage
 
                # build page
                init_title(v, doc)
-               init_sidebar(v, doc)
                init_topmenu(v, doc)
                init_content(v, doc)
+               init_sidebar(v, doc)
 
                # piwik tracking
                var tracker_url = v.ctx.opt_piwik_tracker.value
@@ -211,11 +211,14 @@ redef class DocPage
 
        # Build page sidebar if any.
        fun init_sidebar(v: RenderHTMLPhase, doc: DocModel) do
-               sidebar = new TplSidebar
+               sidebar = new DocSideBar
+               sidebar.boxes.add new DocSideBox("Summary", html_toc)
        end
 
        # Build page content template.
-       fun init_content(v: RenderHTMLPhase, doc: DocModel) do end
+       fun init_content(v: RenderHTMLPhase, doc: DocModel) do
+               root.init_html_render(v, doc, self)
+       end
 end
 
 redef class OverviewPage
@@ -260,8 +263,6 @@ redef class OverviewPage
                section.add_child ssection
                self.add_section section
        end
-
-       redef fun init_sidebar(v, doc) do sidebar = new TplSidebar
 end
 
 redef class SearchPage
@@ -362,7 +363,8 @@ redef class MGroupPage
                for mclass in sorted do
                        list.add_li tpl_sidebar_item(mclass)
                end
-               sidebar.boxes.add new TplSideBox.with_content("All classes", list)
+               sidebar.boxes.add new DocSideBox("All classes", list)
+               sidebar.boxes.last.is_open = false
        end
 
        private fun tpl_sidebar_item(def: MClass): TplListItem do
@@ -403,7 +405,8 @@ redef class MModulePage
                for mclass in sorted do
                        list.add_li tpl_sidebar_item(mclass)
                end
-               sidebar.boxes.add new TplSideBox.with_content("All classes", list)
+               sidebar.boxes.add new DocSideBox("All classes", list)
+               sidebar.boxes.last.is_open = false
        end
 
        private fun tpl_sidebar_item(def: MClass): TplListItem do
@@ -437,7 +440,8 @@ redef class MClassPage
 
                by_kind.sort_groups(v.name_sorter)
                for g in by_kind.groups do tpl_sidebar_list(g, summary)
-               sidebar.boxes.add new TplSideBox.with_content("All properties", summary)
+               sidebar.boxes.add new DocSideBox("All properties", summary)
+               sidebar.boxes.last.is_open = false
        end
 
        private fun tpl_sidebar_list(mprops: PropertyGroup[MProperty], summary: TplList) do
@@ -521,6 +525,13 @@ redef class DocComposite
        #
        # FIXME needed to maintain TplSection compatibility.
        fun render(v: RenderHTMLPhase, doc: DocModel, page: MEntityPage, parent: TplSectionElt) is abstract
+
+       # Prepares the HTML rendering for this element.
+       #
+       # This visit is mainly used to set template attributes before rendering.
+       fun init_html_render(v: RenderHTMLPhase, doc: DocModel, page: DocPage) do
+               for child in children do child.init_html_render(v, doc, page)
+       end
 end
 
 redef class DocRoot
@@ -660,6 +671,7 @@ redef class DefinitionArticle
                        if mentity.is_intro and mentity.mmodule != page.mentity then
                                article.content = mentity.html_short_comment
                        end
+                       if page isa MModulePage then is_toc_hidden = true
                else if mentity isa MPropDef then
                        if page.mentity isa MClass then
                                title = new Template
@@ -697,7 +709,7 @@ redef class DefinitionArticle
                                title.add "in "
                                title.add mentity.mclassdef.html_link
                                article.title = title
-                               article.summary_title = "in {mentity.mclassdef.html_name}"
+                               toc_title = "in {mentity.mclassdef.html_name}"
                        end
                        article.source_link = v.tpl_showsource(mentity.location)
                end
@@ -792,22 +804,12 @@ redef class GraphArticle
                file.close
                sys.system("\{ test -f {path_sh}.png && test -f {path_sh}.s.dot && diff -- {path_sh}.dot {path_sh}.s.dot >/dev/null 2>&1 ; \} || \{ cp -- {path_sh}.dot {path_sh}.s.dot && dot -Tpng -o{path_sh}.png -Tcmapx -o{path_sh}.map {path_sh}.s.dot ; \}")
                var fmap = new FileReader.open("{path}.map")
-               var map = fmap.read_all
+               map = fmap.read_all
                fmap.close
 
                var article = new TplArticle("graph")
-               var alt = ""
-               # FIXME diff hack
-               # if title != null then
-                       # article.title = title
-                       # alt = "alt='{title.html_escape}'"
-               # end
                article.css_classes.add "text-center"
-               var content = new Template
-               var name_html = id.html_escape
-               content.add "<img src='{name_html}.png' usemap='#{name_html}' style='margin:auto' {alt}/>"
-               content.add map
-               article.content = content
+               article.content = write_to_string
                parent.add_child article
        end
 end