doc/src: GraphArticle use new templates
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 24 Feb 2015 00:06:43 +0000 (01:06 +0100)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 25 Apr 2015 13:22:50 +0000 (09:22 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

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

index 66ef564..0a011e8 100644 (file)
@@ -73,7 +73,7 @@ redef class MModulePage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(mentity, name, op)
+               return new GraphArticle(mentity, name, "Importation Graph", op)
        end
 end
 
@@ -107,7 +107,7 @@ redef class MClassPage
                        end
                end
                op.append("\}\n")
-               return new GraphArticle(mentity, name, op)
+               return new GraphArticle(mentity, name, "Inheritance Graph", op)
        end
 end
 
@@ -121,6 +121,9 @@ class GraphArticle
        # Graph ID (used for outputing file with names).
        var id: String
 
+       # Graph title to display.
+       var graph_title: String
+
        # Dot script of the graph.
        var dot: Text
 end
index f19922f..ec7f7df 100644 (file)
@@ -215,7 +215,9 @@ redef class DocPage
        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
@@ -521,6 +523,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
@@ -792,22 +801,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
index 0152a85..8340507 100644 (file)
@@ -19,6 +19,7 @@ import html_model
 import html::bootstrap
 import doc_phases::doc_structure
 import doc_phases::doc_hierarchies
+import doc_phases::doc_graphs
 import doc_phases::doc_intros_redefs
 
 # Renders the page as HTML.
@@ -331,3 +332,21 @@ redef class IntrosRedefsListArticle
                add lst
        end
 end
+
+redef class GraphArticle
+       redef var html_id is lazy do return "article_graph_{mentity.nitdoc_id}"
+       redef var is_hidden = false
+
+       # HTML map used to display link.
+       #
+       # This attribute is set by the `doc_render` phase who knows the context.
+       var map: String is noinit, writable
+
+       redef fun render_body do
+               addn "<div class=\"text-center\">"
+               addn " <img src='{id}.png' usemap='#{id}' style='margin:auto'"
+               addn "  alt='{graph_title}'/>"
+               add map
+               addn "</div>"
+       end
+end