From abbddf4db1125c58b961e1c9b6ea796aa0a63407 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 1 May 2018 15:32:43 -0400 Subject: [PATCH] doc/commands: generate CmdEntityLink command to HTML Signed-off-by: Alexandre Terrasa --- src/doc/commands/commands_html.nit | 8 +++++++ src/doc/commands/tests/test_commands_html.nit | 6 ++++++ .../tests/test_commands_html.sav/test_cmd_link.res | 1 + src/doc/templates/templates_html.nit | 22 ++++++++++++-------- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res diff --git a/src/doc/commands/commands_html.nit b/src/doc/commands/commands_html.nit index 7ca545c..7822eb2 100644 --- a/src/doc/commands/commands_html.nit +++ b/src/doc/commands/commands_html.nit @@ -104,6 +104,14 @@ redef class CmdComment end end +redef class CmdEntityLink + redef fun to_html do + var mentity = self.mentity + if mentity == null then return "" + return mentity.html_link(text, title).write_to_string + end +end + redef class CmdEntityCode redef fun to_html do var output = render_code(node) diff --git a/src/doc/commands/tests/test_commands_html.nit b/src/doc/commands/tests/test_commands_html.nit index f88e425..fefb1c7 100644 --- a/src/doc/commands/tests/test_commands_html.nit +++ b/src/doc/commands/tests/test_commands_html.nit @@ -40,6 +40,12 @@ class TestCommandsHtml print_html cmd.to_html end + fun test_cmd_link is test do + var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character") + cmd.init_command + print_html cmd.to_html + end + # CmdInheritance fun test_cmd_parents is test do diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res new file mode 100644 index 0000000..4ed025b --- /dev/null +++ b/src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res @@ -0,0 +1 @@ +Character diff --git a/src/doc/templates/templates_html.nit b/src/doc/templates/templates_html.nit index 30a2817..7a51f06 100644 --- a/src/doc/templates/templates_html.nit +++ b/src/doc/templates/templates_html.nit @@ -40,13 +40,15 @@ redef class MEntity # # You should redefine this method depending on the organization or your # output. - fun html_link: Link do - var title = null + fun html_link(text, title: nullable String): Link do + if text == null then + text = html_name + end var mdoc = self.mdoc_or_fallback - if mdoc != null then + if title == null and mdoc != null then title = mdoc.synopsis.html_escape end - return new Link(html_url, html_name, title) + return new Link(html_url, text, title) end # Returns the complete MEntity declaration decorated with HTML @@ -273,7 +275,7 @@ redef class MMethodDef end redef class MVirtualTypeProp - redef fun html_link do return mvirtualtype.html_link + redef fun html_link(text, title) do return mvirtualtype.html_link(text, title) end redef class MVirtualTypeDef @@ -292,7 +294,7 @@ redef class MType end redef class MClassType - redef fun html_link do return mclass.html_link + redef fun html_link(text, title) do return mclass.html_link(text, title) end redef class MNullableType @@ -320,13 +322,15 @@ redef class MGenericType end redef class MParameterType - redef fun html_link do - return new Link("{mclass.html_url}#FT_{name.to_cmangle}", name, "formal type") + redef fun html_link(text, title) do + if text == null then text = name + if title == null then title = "formal type" + return new Link("{mclass.html_url}#FT_{name.to_cmangle}", text, title) end end redef class MVirtualType - redef fun html_link do return mproperty.intro.html_link + redef fun html_link(text, title) do return mproperty.intro.html_link(text, title) end redef class MSignature -- 1.7.9.5