From 34c00330a01b530e87f21755d6599745ddefd4fe Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 23 Feb 2015 18:02:12 +0100 Subject: [PATCH] src/doc: uniformize name display Signed-off-by: Alexandre Terrasa --- src/doc/doc_phases/doc_html.nit | 48 +++++++++++++---------------- src/doc/html_templates/html_model.nit | 53 +++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 43 deletions(-) diff --git a/src/doc/doc_phases/doc_html.nit b/src/doc/doc_phases/doc_html.nit index 75c76d7..7d38bc0 100644 --- a/src/doc/doc_phases/doc_html.nit +++ b/src/doc/doc_phases/doc_html.nit @@ -325,7 +325,7 @@ end redef class MEntityPage redef var html_url is lazy do return mentity.nitdoc_url - redef fun init_title(v, doc) do title = mentity.nitdoc_name + 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 @@ -338,9 +338,9 @@ redef class MGroupPage super var mproject = mentity.mproject if not mentity.is_root then - topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.nitdoc_name)) + topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.html_name)) end - topmenu.add_li new ListItem(new Link(html_url, mproject.nitdoc_name)) + topmenu.add_li new ListItem(new Link(html_url, mproject.html_name)) topmenu.active_item = topmenu.items.last end @@ -378,8 +378,8 @@ redef class MModulePage redef fun init_topmenu(v, doc) do super var mproject = mentity.mproject - topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.nitdoc_name)) - topmenu.add_li new ListItem(new Link(mentity.nitdoc_url, mentity.nitdoc_name)) + topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.html_name)) + topmenu.add_li new ListItem(new Link(mentity.nitdoc_url, mentity.html_name)) topmenu.active_item = topmenu.items.last end @@ -417,15 +417,11 @@ end redef class MClassPage - redef fun init_title(v, doc) do - title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}" - end - redef fun init_topmenu(v, doc) do super var mproject = mentity.intro_mmodule.mgroup.mproject - topmenu.add_li new ListItem(new Link("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")) - topmenu.add_li new ListItem(new Link(html_url, mentity.nitdoc_name)) + topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.html_name)) + topmenu.add_li new ListItem(new Link(html_url, mentity.html_name)) topmenu.active_item = topmenu.items.last end @@ -456,7 +452,7 @@ redef class MClassPage classes.add "inherit" var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url var def_url = "{cls_url}#{mprop.nitdoc_id}" - var lnk = new TplLink(def_url, mprop.nitdoc_name) + var lnk = new TplLink(def_url, mprop.html_name) var mdoc = mprop.intro.mdoc_or_fallback if mdoc != null then lnk.title = mdoc.short_comment var item = new Template @@ -500,7 +496,7 @@ end redef class MPropertyPage redef fun init_title(v, doc) do - title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}" + title = "{mentity.html_name}{mentity.tpl_signature.write_to_string}" end redef fun init_topmenu(v, doc) do @@ -508,9 +504,9 @@ redef class MPropertyPage var mmodule = mentity.intro_mclassdef.mmodule var mproject = mmodule.mgroup.mproject var mclass = mentity.intro_mclassdef.mclass - topmenu.add_li new ListItem(new Link("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")) - topmenu.add_li new ListItem(new Link("{mclass.nitdoc_url}", "{mclass.nitdoc_name}")) - topmenu.add_li new ListItem(new Link(html_url, mentity.nitdoc_name)) + topmenu.add_li new ListItem(new Link(mproject.nitdoc_url, mproject.html_name)) + topmenu.add_li new ListItem(new Link(mclass.nitdoc_url, mclass.html_name)) + topmenu.add_li new ListItem(new Link(html_url, mentity.html_name)) topmenu.active_item = topmenu.items.last end end @@ -530,18 +526,16 @@ redef class DocRoot fun start_rendering(v: RenderHTMLPhase, doc: DocModel, page: MEntityPage): TplSection do var section = new TplSection("top") var mentity = page.mentity - section.title = mentity.nitdoc_name + section.title = mentity.html_name section.subtitle = mentity.tpl_declaration # FIXME ugly hack to avoid diff if mentity isa MGroup and mentity.is_root then - section.title = mentity.mproject.nitdoc_name + section.title = mentity.mproject.html_name section.subtitle = mentity.mproject.tpl_declaration - else if mentity isa MClass then - section.title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}" else if mentity isa MProperty then - section.title = "{mentity.nitdoc_name}{mentity.intro.tpl_signature.write_to_string}" + section.title = "{mentity.html_name}{mentity.intro.tpl_signature.write_to_string}" section.subtitle = mentity.tpl_namespace - section.summary_title = mentity.nitdoc_name + section.summary_title = mentity.html_name end render(v, doc, page, section) return section @@ -576,10 +570,10 @@ redef class ConcernSection var title = new Template if mmodule == page.mentity then title.add "in " - section.summary_title = "in {mmodule.nitdoc_name}" + section.summary_title = "in {mmodule.html_name}" else title.add "from " - section.summary_title = "from {mmodule.nitdoc_name}" + section.summary_title = "from {mmodule.html_name}" end title.add mmodule.tpl_namespace section.title = title @@ -590,7 +584,7 @@ redef class ConcernSection title.add "in " title.add mmodule.tpl_namespace section.title = title - section.summary_title = "in {mmodule.nitdoc_name}" + section.summary_title = "in {mmodule.html_name}" end end @@ -711,14 +705,14 @@ redef class DefinitionArticle else var cls_url = mprop.intro.mclassdef.mclass.nitdoc_url var def_url = "{cls_url}#{mprop.nitdoc_id}" - var lnk = new TplLink.with_title(def_url, mprop.nitdoc_name, + var lnk = new TplLink.with_title(def_url, mprop.html_name, "Go to introduction") title.add "redef " title.add lnk end article.title = title article.title_classes.add "signature" - article.summary_title = "{mprop.nitdoc_name}" + article.summary_title = "{mprop.html_name}" article.subtitle = mpropdef.tpl_namespace if mpropdef.mdoc_or_fallback != null then article.content = mpropdef.mdoc_or_fallback.tpl_comment diff --git a/src/doc/html_templates/html_model.nit b/src/doc/html_templates/html_model.nit index 15b2963..2908fad 100644 --- a/src/doc/html_templates/html_model.nit +++ b/src/doc/html_templates/html_model.nit @@ -45,9 +45,20 @@ redef class MEntity # URL of this entity’s Nitdoc page. fun nitdoc_url: String is abstract + # Returns the mentity name without short signature. + # + # * MProject: `foo` + # * MGroup: `foo` + # * MModule: `foo` + # * MClass: `Foo[E]` + # * MClassDef: `Foo[E]` + # * MProperty: `foo(e)` + # * MPropdef: `foo(e)` + var html_name: String is lazy do return name.html_escape + # A template link to the mentity `nitdoc_id` fun tpl_anchor: TplLink do - var tpl = new TplLink("#{nitdoc_id}", nitdoc_name) + var tpl = new TplLink("#{nitdoc_id}", html_name) var mdoc = mdoc_or_fallback if mdoc != null then tpl.title = mdoc.short_comment @@ -57,7 +68,7 @@ redef class MEntity # A template link to the mentity `nitdoc_url` fun tpl_link: TplLink do - var tpl = new TplLink(nitdoc_url, nitdoc_name) + var tpl = new TplLink(nitdoc_url, html_name) var mdoc = mdoc_or_fallback if mdoc != null then tpl.title = mdoc.short_comment @@ -80,7 +91,7 @@ redef class MEntity var tpl = new TplArticle.with_title(nitdoc_id, tpl_title) tpl.title_classes.add "signature" tpl.subtitle = tpl_namespace - tpl.summary_title = nitdoc_name + tpl.summary_title = html_name return tpl end @@ -252,6 +263,22 @@ redef class MClass redef fun nitdoc_url do return "class_{nitdoc_id}.html" redef fun mdoc_or_fallback do return intro.mdoc + # Format: `Foo[E]` + redef var html_name is lazy do + var tpl = new Template + tpl.add name.html_escape + if arity > 0 then + tpl.add "[" + var parameter_names = new Array[String] + for p in mparameters do + parameter_names.add(p.html_name) + end + tpl.add parameter_names.join(", ") + tpl.add "]" + end + return tpl.write_to_string + end + redef fun tpl_declaration do return intro.tpl_declaration redef fun tpl_definition do return intro.tpl_definition @@ -268,7 +295,6 @@ redef class MClass var title = new Template title.add tpl_icon title.add tpl_link - title.add tpl_signature return title end @@ -280,7 +306,7 @@ redef class MClass tpl.add "[" var parameter_names = new Array[String] for p in mparameters do - parameter_names.add(p.nitdoc_name) + parameter_names.add(p.html_name) end tpl.add parameter_names.join(", ") tpl.add "]" @@ -288,12 +314,6 @@ redef class MClass return tpl end - redef fun tpl_article do - var tpl = super - tpl.summary_title = "{nitdoc_name}{tpl_signature.write_to_string}" - return tpl - end - redef fun tpl_css_classes do return intro.tpl_css_classes end @@ -314,7 +334,7 @@ redef class MClassDef redef fun tpl_article do var tpl = new TplArticle(nitdoc_id) - tpl.summary_title = "in {mmodule.nitdoc_name}" + tpl.summary_title = "in {mmodule.html_name}" tpl.title = tpl_declaration tpl.title_classes.add "signature" var title = new Template @@ -332,7 +352,6 @@ redef class MClassDef var title = new Template title.add tpl_icon title.add tpl_link - title.add tpl_signature return title end @@ -350,7 +369,7 @@ redef class MClassDef if not mparameters.is_empty then tpl.add "[" for i in [0..mparameters.length[ do - tpl.add "{mparameters[i].nitdoc_name}: " + tpl.add "{mparameters[i].html_name}: " tpl.add bound_mtype.arguments[i].tpl_signature if i < mparameters.length - 1 then tpl.add ", " end @@ -428,7 +447,7 @@ redef class MPropDef redef fun tpl_article do var tpl = new TplArticle(nitdoc_id) - tpl.summary_title = "in {mclassdef.nitdoc_name}" + tpl.summary_title = "in {mclassdef.html_name}" var title = new Template title.add "in " title.add mclassdef.tpl_link @@ -577,7 +596,9 @@ end redef class MGenericType redef fun tpl_signature do var tpl = new Template - tpl.add tpl_link + var lnk = tpl_link + lnk.text = mclass.name.html_escape + tpl.add lnk tpl.add "[" for i in [0..arguments.length[ do tpl.add arguments[i].tpl_signature -- 1.7.9.5