doc/commands: generate CmdEntityLink command to HTML
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 1 May 2018 19:32:43 +0000 (15:32 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:03:34 +0000 (19:03 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/commands_html.nit
src/doc/commands/tests/test_commands_html.nit
src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res [new file with mode: 0644]
src/doc/templates/templates_html.nit

index 7ca545c..7822eb2 100644 (file)
@@ -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)
index f88e425..fefb1c7 100644 (file)
@@ -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 (file)
index 0000000..4ed025b
--- /dev/null
@@ -0,0 +1 @@
+<a href="test_prog_58d_58dCharacter" title="Characters can be played by both the human or the machine.">Character</a>
index 30a2817..7a51f06 100644 (file)
@@ -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