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.
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