From aafc2a6d4721a8a2db688563113f5025e3a91b8a Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 24 Feb 2015 01:06:43 +0100 Subject: [PATCH] doc/src: GraphArticle use new templates Signed-off-by: Alexandre Terrasa --- src/doc/doc_phases/doc_graphs.nit | 7 +++++-- src/doc/doc_phases/doc_html.nit | 25 ++++++++++++------------- src/doc/html_templates/html_templates.nit | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/doc/doc_phases/doc_graphs.nit b/src/doc/doc_phases/doc_graphs.nit index 66ef564..0a011e8 100644 --- a/src/doc/doc_phases/doc_graphs.nit +++ b/src/doc/doc_phases/doc_graphs.nit @@ -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 diff --git a/src/doc/doc_phases/doc_html.nit b/src/doc/doc_phases/doc_html.nit index f19922f..ec7f7df 100644 --- a/src/doc/doc_phases/doc_html.nit +++ b/src/doc/doc_phases/doc_html.nit @@ -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 "" - content.add map - article.content = content + article.content = write_to_string parent.add_child article end end diff --git a/src/doc/html_templates/html_templates.nit b/src/doc/html_templates/html_templates.nit index 0152a85..8340507 100644 --- a/src/doc/html_templates/html_templates.nit +++ b/src/doc/html_templates/html_templates.nit @@ -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 "
" + addn " {graph_title}" + add map + addn "
" + end +end -- 1.7.9.5