src/doc: move rendering from old templates to new phases
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 25 Apr 2015 13:34:33 +0000 (09:34 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 5 May 2015 15:56:57 +0000 (11:56 -0400)
Next commits will do some fixups:
* redo showlinks
* redo Overview
* redo FullIndex page

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_phases/doc_html.nit
src/doc/html_templates/html_templates.nit

index 5004408..2d806cd 100644 (file)
@@ -261,7 +261,6 @@ redef class OverviewPage
                        ssection.add_child sarticle
                end
                section.add_child ssection
-               self.add_section section
        end
 end
 
@@ -300,7 +299,6 @@ redef class SearchPage
                        tpl.props.add m
                end
                section.add_child tpl
-               self.add_section section
        end
 
        # Extract mmodule list to display (sorted by name)
@@ -332,7 +330,6 @@ end
 redef class MEntityPage
        redef var html_url is lazy do return mentity.nitdoc_url
        redef fun init_title(v, doc) do title = mentity.html_name
-       redef fun init_content(v, doc) do add_section root.start_rendering(v, doc, self)
 end
 
 # FIXME all clases below are roughly copied from `doc_pages` and adapted to new
@@ -526,11 +523,6 @@ redef class MPropertyPage
 end
 
 redef class DocComposite
-       # Render this DocComposite as HTML.
-       #
-       # 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.
@@ -539,151 +531,108 @@ redef class DocComposite
        end
 end
 
-redef class DocRoot
-
-       # Start the rendering from root.
-       #
-       # FIXME needed to maintain TplSection compatibility.
-       fun start_rendering(v: RenderHTMLPhase, doc: DocModel, page: MEntityPage): TplSection do
-               var section = new TplSection("top")
-               var mentity = page.mentity
-               section.title = mentity.html_name
-               section.subtitle = mentity.html_declaration
-               # FIXME ugly hack to avoid diff
+# FIXME hideous hacks to avoid diff
+redef class MEntitySection
+       redef fun init_html_render(v, doc, page) do
+               if not page isa MEntityPage then return
+               var mentity = self.mentity
                if mentity isa MGroup and mentity.is_root then
-                       section.title = mentity.mproject.html_name
-                       section.subtitle = mentity.mproject.html_declaration
+                       html_title = mentity.mproject.html_name
+                       html_subtitle = mentity.mproject.html_declaration
                else if mentity isa MProperty then
-                       section.title = "{mentity.html_name}{mentity.intro.html_signature.write_to_string}"
-                       section.subtitle = mentity.html_namespace
-                       section.summary_title = mentity.html_name
-               end
-               render(v, doc, page, section)
-               return section
-       end
-
-       redef fun render(v, doc, page, parent) do
-               for child in children do
-                       child.render(v, doc, page, parent)
+                       var title = new Template
+                       title.add mentity.html_name
+                       title.add mentity.html_signature
+                       html_title = title
+                       html_subtitle = mentity.html_namespace
+                       toc_title = mentity.html_name
                end
+               super
        end
 end
 
+# FIXME hideous hacks to avoid diff
 redef class ConcernSection
-       redef fun render(v, doc, page, parent) do
-               var section = new TplSection(mentity.nitdoc_id)
+       redef fun init_html_render(v, doc, page) do
+               if not page isa MEntityPage then return
                var mentity = self.mentity
-               # FIXME hideous hacks to avoid diff
                if page.mentity isa MModule and mentity isa MModule then
-                       render_concern_mmodule(page, section, mentity)
-               else if page.mentity isa MClass and mentity isa MModule then
-                       render_concern_other(page, section, mentity)
-               else if page.mentity isa MProperty and mentity isa MModule then
-                       render_concern_other(page, section, mentity)
-               end
-               for child in children do
-                       child.render(v, doc, page, section)
-               end
-               parent.add_child section
-       end
-
-       private fun render_concern_mmodule(page: MEntityPage, section: TplSection, mmodule: MModule) do
-               var title = new Template
-               if mmodule == page.mentity then
+                       var title = new Template
+                       if mentity == page.mentity then
+                               title.add "in "
+                               toc_title = "in {mentity.html_name}"
+                       else
+                               title.add "from "
+                               toc_title = "from {mentity.html_name}"
+                       end
+                       title.add mentity.html_namespace
+                       html_title = title
+               else if (page.mentity isa MClass and mentity isa MModule) or
+                               (page.mentity isa MProperty and mentity isa MModule) then
+                       var title = new Template
                        title.add "in "
-                       section.summary_title = "in {mmodule.html_name}"
-               else
-                       title.add "from "
-                       section.summary_title = "from {mmodule.html_name}"
+                       title.add mentity.html_namespace
+                       html_title = title
+                       toc_title = "in {mentity.html_name}"
                end
-               title.add mmodule.html_namespace
-               section.title = title
-       end
-
-       private fun render_concern_other(page: MEntityPage, section: TplSection, mmodule: MModule) do
-               var title = new Template
-               title.add "in "
-               title.add mmodule.html_namespace
-               section.title = title
-               section.summary_title = "in {mmodule.html_name}"
-       end
-end
-
-redef class MEntitySection
-       redef fun render(v, doc, page, parent) do
-               for child in children do child.render(v, doc, page, parent)
+               super
        end
 end
 
+# TODO redo showlink
 redef class IntroArticle
-       redef fun render(v, doc, page, parent) do
-               var article = new TplArticle("intro")
+       redef fun init_html_render(v, doc, page) do
                var mentity = self.mentity
                if mentity isa MModule then
-                       article.source_link = v.tpl_showsource(mentity.location)
+                       # article.source_link = v.tpl_showsource(mentity.location)
                else if mentity isa MClassDef then
-                       article.source_link = v.tpl_showsource(mentity.location)
+                       # article.source_link = v.tpl_showsource(mentity.location)
                else if mentity isa MPropDef then
-                       article.source_link = v.tpl_showsource(mentity.location)
+                       # article.source_link = v.tpl_showsource(mentity.location)
                end
-               # article.subtitle = mentity.html_declaration
-               article.content = write_to_string
-               parent.add_child article
-       end
-end
-
-redef class ConcernsArticle
-       redef fun render(v, doc, page, parent) do
-               parent.add_child new TplArticle.
-                       with_content("concerns", "Concerns", write_to_string)
        end
 end
 
+# FIXME less hideous hacks...
 redef class DefinitionArticle
-       redef fun render(v, doc, page, parent) do
-               var title = new Template
-               title.add mentity.html_icon
-               title.add mentity.html_name
-
-               var article = new TplArticle(mentity.nitdoc_id)
-               article.title = title
-               article.title_classes.add "signature"
-               article.subtitle = mentity.html_declaration
-               article.summary_title = mentity.html_name
-               article.content = write_to_string
-
-               # FIXME less hideous hacks...
+       redef fun init_html_render(v, doc, page) do
+               if not page isa MEntityPage then return
                var mentity = self.mentity
                if mentity isa MModule then
-                       title = new Template
+                       var title = new Template
                        title.add mentity.html_icon
                        title.add mentity.html_namespace
-                       article.title = title
+                       html_title = title
+                       toc_title = mentity.html_name
+                       # article.source_link = v.tpl_showsource(mentity.location)
                else if mentity isa MClass then
-                       title = new Template
+                       var title = new Template
                        title.add mentity.html_icon
                        title.add mentity.html_link
-                       article.title = title
-                       article.subtitle = mentity.html_namespace
-                       article.content = null
+                       html_title = title
+                       html_subtitle = mentity.html_namespace
+                       toc_title = mentity.html_name
+                       is_no_body = true
                else if mentity isa MClassDef then
-                       title = new Template
+                       var title = new Template
                        title.add "in "
                        title.add mentity.mmodule.html_namespace
-                       article.title = mentity.html_declaration
-                       article.subtitle = title
-                       article.source_link = v.tpl_showsource(mentity.location)
+                       html_title = mentity.html_declaration
+                       html_subtitle = title
+                       toc_title = "in {mentity.html_name}"
+                       # article.source_link = v.tpl_showsource(mentity.location)
                        if mentity.is_intro and mentity.mmodule != page.mentity then
-                               article.content = mentity.html_short_comment
+                               is_short_comment = true
                        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
+                               var title = new Template
                                title.add mentity.html_icon
                                title.add mentity.html_declaration
-                               article.title = title
-                               article.subtitle = mentity.html_namespace
+                               html_title = title
+                               html_subtitle = mentity.html_namespace
+                               toc_title = mentity.html_name
                                # TODO move in its own phase? let's see after doc_template refactoring.
                                # Add linearization
                                var all_defs = new HashSet[MPropDef]
@@ -699,29 +648,29 @@ redef class DefinitionArticle
                                var lin = all_defs.to_a
                                doc.mainmodule.linearize_mpropdefs(lin)
                                if lin.length > 1 then
-                                       var lin_article = new TplArticle("{mentity.nitdoc_id}.lin")
-                                       lin_article.title = "Inheritance"
+                                       var lin_article = new DocArticle
+                                       lin_article.html_id = "{mentity.nitdoc_id}.lin"
+                                       lin_article.html_title = "Inheritance"
+                                       lin_article.is_toc_hidden = true
                                        var lst = new UnorderedList
                                        lst.css_classes.add("list-unstyled list-labeled")
                                        for smpropdef in lin do
                                                lst.add_li tpl_inheritance_item(smpropdef)
                                        end
-                                       lin_article.content = lst
-                                       article.add_child lin_article
+                                       # FIXME will be moved in its own phase
+                                       lin_article.add lst
+                                       add_child lin_article
                                end
                        else
-                               title = new Template
+                               var title = new Template
                                title.add "in "
                                title.add mentity.mclassdef.html_link
-                               article.title = title
+                               html_title = title
                                toc_title = "in {mentity.mclassdef.html_name}"
                        end
-                       article.source_link = v.tpl_showsource(mentity.location)
-               end
-               for child in children do
-                       child.render(v, doc, page, article)
+                       # article.source_link = v.tpl_showsource(mentity.location)
                end
-               parent.add_child article
+               super
        end
 
        # Filter `page.mpropdefs` for this `mpropertie`.
@@ -758,49 +707,8 @@ redef class DefinitionArticle
        end
 end
 
-redef class IntrosRedefsListArticle
-       redef fun render(v, doc, page, parent) do
-               if mentities.is_empty then return
-               var article = new TplArticle.with_title(list_title.to_lower, list_title)
-               article.content = write_to_string
-               parent.add_child article
-       end
-end
-
-# FIXME compatibility with doc_templates.
-redef class ImportationListSection
-       redef fun render(v, doc, page, parent) do
-               var section = new TplSection.with_title("dependencies", "Dependencies")
-               for child in children do
-                       child.render(v, doc, page, section)
-               end
-               parent.add_child section
-       end
-end
-
-# FIXME compatibility with doc_templates.
-redef class InheritanceListSection
-       redef fun render(v, doc, page, parent) do
-               var section = new TplSection.with_title("inheritance", "Inheritance")
-               for child in children do
-                       child.render(v, doc, page, section)
-               end
-               parent.add_child section
-       end
-end
-
-# FIXME compatibility with doc_templates.
-redef class HierarchyListArticle
-       redef fun render(v, doc, page, parent) do
-               if mentities.is_empty then return
-               var article = new TplArticle.with_title(list_title.to_lower, list_title)
-               article.content = write_to_string
-               parent.add_child article
-       end
-end
-
 redef class GraphArticle
-       redef fun render(v, doc, page, parent) do
+       redef fun init_html_render(v, doc, page) do
                var output_dir = v.ctx.output_dir
                var path = output_dir / id
                var path_sh = path.escape_to_sh
@@ -809,13 +717,8 @@ 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")
-               map = fmap.read_all
+               self.map = fmap.read_all
                fmap.close
-
-               var article = new TplArticle("graph")
-               article.css_classes.add "text-center"
-               article.content = write_to_string
-               parent.add_child article
        end
 end
 
index 1aa3c02..f4006de 100644 (file)
@@ -41,22 +41,12 @@ redef class DocPage
        # Sidebar template if any.
        var sidebar: nullable DocSideBar = null is writable
 
-       # Content of the page in form a TplSection.
-       # TODO remove when other templates are migrated.
-       var sections = new Array[TplSection]
-
        # Footer content if any.
        var footer: nullable Writable = null is writable
 
        # JS scripts to append at the end of the body
        var scripts = new Array[TplScript]
 
-       # Adds a section to this page.
-       # TODO remove when other templates are migrated.
-       fun add_section(section: TplSection) do
-               sections.add section
-       end
-
        # Renders the html `<head>`.
        private fun render_head do
                var css = (self.shareurl / "css").html_escape
@@ -81,7 +71,7 @@ redef class DocPage
 
        # Renders the footer and content.
        private fun render_content do
-               for section in sections do add section
+               add root
                if footer != null then
                        addn "<div class='well footer'>"
                        add footer.as(not null)
@@ -256,7 +246,7 @@ redef class DocComposite
        super Template
 
        # HTML anchor id
-       var html_id: String is noinit
+       var html_id: String is noinit, writable
 
        # Title to display if any.
        #
@@ -269,7 +259,10 @@ redef class DocComposite
        # Render the element title and subtitle.
        private fun render_title do
                if html_title != null then
-                       addn new Header(hlvl, html_title.write_to_string)
+               var header = new Header(hlvl, html_title.write_to_string)
+               header.css_classes.add "signature"
+               if hlvl == 2 then header.css_classes.add "well well-sm"
+               addn header
                end
                if html_subtitle != null then
                        addn "<div class='info subtitle'>"
@@ -279,7 +272,9 @@ redef class DocComposite
        end
 
        # Render the element body.
-       private fun render_body do end
+       private fun render_body do
+               for child in children do addn child.write_to_string
+       end
 
        redef fun rendering do
                if is_hidden then return
@@ -289,7 +284,7 @@ redef class DocComposite
 
        # Level <hX> for HTML heading.
        private fun hlvl: Int do
-               if parent == null then return 1
+               if parent == null then return 0
                return parent.hlvl + 1
        end
 
@@ -333,18 +328,23 @@ redef class DocSection
                        addn "<a id=\"{html_id}\"></a>"
                        return
                end
+               addn "<section{render_css_classes} id=\"{html_id}\">"
+               render_title
                render_body
+               addn "</section>"
        end
 end
 
 redef class DocArticle
        super BSComponent
 
-       # Never displays the title for article.
-       #
-       # This is to maintain compatibility with old components, this may change
-       # without notice in further version.
-       redef fun render_title do end
+       redef fun rendering do
+               if is_hidden then return
+               addn "<article{render_css_classes} id=\"{html_id}\">"
+               render_title
+               render_body
+               addn "</article>"
+       end
 end
 
 redef class MEntityComposite
@@ -352,6 +352,12 @@ redef class MEntityComposite
        redef var html_title is lazy do return mentity.nitdoc_name
 end
 
+redef class MEntitySection
+       redef var html_id is lazy do return "section_{mentity.nitdoc_name}"
+       redef var html_title is lazy do return mentity.html_name
+       redef var html_subtitle is lazy do return mentity.html_declaration
+end
+
 redef class ConcernSection
        redef var html_id is lazy do return "section_concerns_{mentity.nitdoc_id}"
        redef var html_title is lazy do return "in {mentity.nitdoc_name}"
@@ -370,7 +376,7 @@ end
 
 redef class IntroArticle
        redef var html_id is lazy do return "article_intro_{mentity.nitdoc_id}"
-       redef var html_title is lazy do return null
+       redef var html_title = null
        redef var is_hidden = false
        redef var is_toc_hidden = true
 
@@ -394,9 +400,26 @@ redef class DefinitionArticle
        redef var html_subtitle is lazy do return mentity.html_declaration
        redef var is_hidden = false
 
+       # Does `self` display only it's title and no body?
+       #
+       # FIXME diff hack
+       var is_no_body: Bool = false is writable
+
+       # Does `self` display only the short content as definition?
+       #
+       # FIXME diff hack
+       var is_short_comment: Bool = false is writable
+
        redef fun render_body do
-               var comment = mentity.html_comment
-               if comment != null then addn comment
+               if not is_no_body then
+                       var comment
+                       if is_short_comment then
+                               comment = mentity.html_short_comment
+                       else
+                               comment = mentity.html_comment
+                       end
+                       if comment != null then addn comment
+               end
                super
        end
 end