From: Alexandre Terrasa Date: Tue, 1 May 2018 19:29:46 +0000 (-0400) Subject: doc/commands: introduce CmdEntityLink command X-Git-Url: http://nitlanguage.org?hp=516fd7c0c6e30a9ba4a7032eb024f9e78fc4a629 doc/commands: introduce CmdEntityLink command Signed-off-by: Alexandre Terrasa --- diff --git a/src/doc/commands/commands_model.nit b/src/doc/commands/commands_model.nit index c359546..a119d45 100644 --- a/src/doc/commands/commands_model.nit +++ b/src/doc/commands/commands_model.nit @@ -93,6 +93,34 @@ class WarningNoMDoc redef fun to_s do return "No documentation for `{mentity.full_name}`." end +# Get the link to a MEntity API documentation +class CmdEntityLink + super CmdEntity + + # The link text to display + var text: nullable String = null is optional, writable + + # The link title to display when the link is hovered + var title: nullable String = null is optional, writable + + redef fun init_command do + var res = super + if not res isa CmdSuccess then return res + var mentity = self.mentity.as(not null) + + if text == null then + text = mentity.name + end + if title == null then + var mdoc = mentity.mdoc_or_fallback + if mdoc != null then + title = mdoc.synopsis + end + end + return res + end +end + # MEntity ancestors command # # Retrieve all the ancestors (direct and indirect) of a MEntity. diff --git a/src/doc/commands/tests/test_commands_model.nit b/src/doc/commands/tests/test_commands_model.nit index a785a09..901dd3e 100644 --- a/src/doc/commands/tests/test_commands_model.nit +++ b/src/doc/commands/tests/test_commands_model.nit @@ -65,6 +65,41 @@ class TestCommandsModel assert res isa WarningNoMDoc end + # CmdLink + + fun test_cmd_link is test do + var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character") + var res = cmd.init_command + assert res isa CmdSuccess + assert cmd.text == "Character" + assert cmd.title == "Characters can be played by both the human or the machine." + end + + fun test_cmd_link_with_text is test do + var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character", text = "foo") + var res = cmd.init_command + assert res isa CmdSuccess + assert cmd.text == "foo" + assert cmd.title == "Characters can be played by both the human or the machine." + end + + fun test_cmd_link_with_title is test do + var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character", title = "bar") + var res = cmd.init_command + assert res isa CmdSuccess + assert cmd.text == "Character" + assert cmd.title == "bar" + end + + fun test_cmd_link_with_text_and_title is test do + var cmd = new CmdEntityLink(test_view, mentity_name = "test_prog::Character", + text = "foo", title = "bar") + var res = cmd.init_command + assert res isa CmdSuccess + assert cmd.text == "foo" + assert cmd.title == "bar" + end + # CmdInheritance fun test_cmd_parents is test do