doc/commands: render `commands_main` as HTML
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:20:19 +0000 (19:20 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 10 May 2018 20:35:10 +0000 (16:35 -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_main_compile.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_mains.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_man_options.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_man_synopsis.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_mentities.res
src/doc/commands/tests/test_commands_html.sav/test_cmd_testing.res [new file with mode: 0644]

index b2ab2a3..8cffb32 100644 (file)
@@ -18,6 +18,7 @@ module commands_html
 import commands::commands_graph
 import commands::commands_usage
 import commands::commands_ini
+import commands::commands_main
 
 import templates::templates_html
 import doc_down
@@ -267,3 +268,57 @@ redef class CmdEntityFileContent
                return "<pre>{content}</pre>"
        end
 end
+
+# Main commands
+
+redef class CmdMains
+       redef fun to_html do return super # FIXME lin
+end
+
+redef class CmdMainCompile
+       redef fun to_html do
+               var command = self.command
+               if command == null then return ""
+
+               return "<pre>{command}</pre>"
+       end
+end
+
+redef class CmdManSynopsis
+       redef fun to_html do
+               var synopsis = self.synopsis
+               if synopsis == null then return ""
+
+               return "<pre>{synopsis}</pre>"
+       end
+end
+
+redef class CmdManOptions
+       redef fun to_html do
+               var options = self.options
+               if options == null or options.is_empty then return ""
+
+               var tpl = new Template
+               tpl.addn "<pre>"
+               tpl.addn "<table width='100%'>"
+               for opt, desc in options do
+                       tpl.addn "<tr>"
+                       tpl.addn "<th valign='top' width='30%'>{opt}</th>"
+                       tpl.addn "<td width='70%'>{desc}</td>"
+                       tpl.addn "</tr>"
+               end
+               tpl.addn "</table>"
+               tpl.addn "</pre>"
+
+               return tpl.write_to_string
+       end
+end
+
+redef class CmdTesting
+       redef fun to_html do
+               var command = self.command
+               if command == null then return ""
+
+               return "<pre>{command}</pre>"
+       end
+end
index 8649179..4b2373b 100644 (file)
@@ -15,6 +15,7 @@
 module test_commands_html is test
 
 import test_commands
+intrude import doc::commands::commands_main
 import doc::commands::commands_html
 
 class TestCommandsHtml
@@ -201,4 +202,53 @@ class TestCommandsHtml
                cmd.file = cmd.file.as(not null).basename # for testing path
                print_html cmd.to_html
        end
+
+       # CmdMain
+
+       fun test_cmd_mains is test do
+               var cmd = new CmdMains(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_main_compile is test do
+               var cmd = new CmdMainCompile(test_view, mentity_name = "test_prog::test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_testing is test do
+               var cmd = new CmdTesting(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_man_synopsis is test do
+               var cmd = new CmdManSynopsis(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_man_options is test do
+               var cmd = new CmdManOptions(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+end
+
+# Avoid path diff
+redef class CmdMainCompile
+       redef fun test_path(file) do
+               if file == null then return null
+               return file.filename.basename
+       end
+end
+
+# Avoid path diff
+redef class CmdTesting
+       redef fun test_path(mentity) do
+               var file = mentity.location.file
+               if file == null then return null
+               return file.filename.basename
+       end
 end
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_main_compile.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_main_compile.res
new file mode 100644 (file)
index 0000000..2a95dcb
--- /dev/null
@@ -0,0 +1 @@
+<pre>nitc test_prog.nit</pre>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_mains.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_mains.res
new file mode 100644 (file)
index 0000000..e00f6c0
--- /dev/null
@@ -0,0 +1 @@
+<ul><li><a href="test_prog_58d_58dtest_prog" title="A test program with a fake model to check model tools.">test_prog</a> - <span class="synopsys nitdoc">A test program with a fake model to check model tools.</span></li></ul>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_man_options.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_man_options.res
new file mode 100644 (file)
index 0000000..876cee2
--- /dev/null
@@ -0,0 +1,13 @@
+<pre>
+<table width='100%'>
+<tr>
+<th valign='top' width='30%'>--opt1</th>
+<td width='70%'>Option 1.</td>
+</tr>
+<tr>
+<th valign='top' width='30%'>--opt2</th>
+<td width='70%'>Option 2.</td>
+</tr>
+</table>
+</pre>
+
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_man_synopsis.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_man_synopsis.res
new file mode 100644 (file)
index 0000000..ca4525e
--- /dev/null
@@ -0,0 +1 @@
+<pre>test_prog [*options*] ARGS...</pre>
index 91afe93..59e52b3 100644 (file)
@@ -1 +1 @@
-<ul><li><a href="test_prog_58d_58dcareers" title="Careers of the game.">careers</a> - <span class="synopsys nitdoc">Careers of the game.</span></li><li><a href="test_prog_58d_58dcharacter" title="Characters are playable entity in the world.">character</a> - <span class="synopsys nitdoc">Characters are playable entity in the world.</span></li><li><a href="test_prog_58d_58dcombat" title="COmbat interactions between characters.">combat</a> - <span class="synopsys nitdoc">COmbat interactions between characters.</span></li><li><a href="excluded_58d_58dexcluded">excluded</a></li><li><a href="test_prog_58d_58dgame" title="A game abstraction for RPG.">game</a> - <span class="synopsys nitdoc">A game abstraction for RPG.</span></li><li><a href="test_prog_58d_58dgame_examples">game_examples</a></li><li><a href="test_prog_58d_58dplatform" title="Declares base types allowed on the platform.">platform</a> - <span class="synopsys nitdoc">Declares base types allowed on the platform.</span></li><li><a href="test_prog_58d_58draces" title="Races of the game.">races</a> - <span class="synopsys nitdoc">Races of the game.</span></li><li><a href="test_prog_58d_58drpg" title="A worlg RPG abstraction.">rpg</a> - <span class="synopsys nitdoc">A worlg RPG abstraction.</span></li><li><a href="test_prog_58d_58dtest_prog" title="A test program with a fake model to check model tools.">test_prog</a> - <span class="synopsys nitdoc">A test program with a fake model to check model tools.</span></li></ul>
+<ul><li><a href="test_prog_58d_58dcareers" title="Careers of the game.">careers</a> - <span class="synopsys nitdoc">Careers of the game.</span></li><li><a href="test_prog_58d_58dcharacter" title="Characters are playable entity in the world.">character</a> - <span class="synopsys nitdoc">Characters are playable entity in the world.</span></li><li><a href="test_prog_58d_58dcombat" title="COmbat interactions between characters.">combat</a> - <span class="synopsys nitdoc">COmbat interactions between characters.</span></li><li><a href="excluded_58d_58dexcluded">excluded</a></li><li><a href="test_prog_58d_58dgame" title="A game abstraction for RPG.">game</a> - <span class="synopsys nitdoc">A game abstraction for RPG.</span></li><li><a href="test_prog_58d_58dgame_examples">game_examples</a></li><li><a href="test_prog_58d_58dplatform" title="Declares base types allowed on the platform.">platform</a> - <span class="synopsys nitdoc">Declares base types allowed on the platform.</span></li><li><a href="test_prog_58d_58draces" title="Races of the game.">races</a> - <span class="synopsys nitdoc">Races of the game.</span></li><li><a href="test_prog_58d_58drpg" title="A worlg RPG abstraction.">rpg</a> - <span class="synopsys nitdoc">A worlg RPG abstraction.</span></li><li><a href="test_prog_58d_58dtest_game">test_game</a></li><li><a href="test_prog_58d_58dtest_prog" title="A test program with a fake model to check model tools.">test_prog</a> - <span class="synopsys nitdoc">A test program with a fake model to check model tools.</span></li></ul>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_testing.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_testing.res
new file mode 100644 (file)
index 0000000..e569191
--- /dev/null
@@ -0,0 +1 @@
+<pre>nitunit tests</pre>