doc/commands: render `commands_ini` as HTML
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:40:06 +0000 (19:40 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 8 May 2018 19:48:00 +0000 (15:48 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

13 files changed:
src/doc/commands/commands_html.nit
src/doc/commands/tests/test_commands_html.nit
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_clone.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file_content.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contributors.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_desc.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_git.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_issues.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file_content.res [new file with mode: 0644]
src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_maintainer.res [new file with mode: 0644]

index 7822eb2..b2ab2a3 100644 (file)
@@ -17,6 +17,7 @@ module commands_html
 
 import commands::commands_graph
 import commands::commands_usage
+import commands::commands_ini
 
 import templates::templates_html
 import doc_down
@@ -171,3 +172,98 @@ redef class CmdGraph
                return output.write_to_string
        end
 end
+
+# Ini commands
+
+redef class CmdIniDescription
+       redef fun to_html do
+               var desc = self.desc
+               if desc == null then return ""
+
+               return "<p>{desc}</p>"
+       end
+end
+
+redef class CmdIniGitUrl
+       redef fun to_html do
+               var url = self.url
+               if url == null then return ""
+
+               return "<a href=\"{url}\">{url}</a>"
+       end
+end
+
+redef class CmdIniCloneCommand
+       redef fun to_html do
+               var command = self.command
+               if command == null then return ""
+
+               return "<pre>{command}</pre>"
+       end
+end
+
+redef class CmdIniIssuesUrl
+       redef fun to_html do
+               var url = self.url
+               if url == null then return ""
+
+               return "<a href=\"{url}\">{url}</a>"
+       end
+end
+
+redef class CmdIniMaintainer
+       redef fun to_html do
+               var name = self.maintainer
+               if name == null then return ""
+
+               return "<b>{name.html_escape}</b>"
+       end
+end
+
+redef class CmdIniContributors
+       redef fun to_html do
+               var names = self.contributors
+               if names == null or names.is_empty then return ""
+
+               var tpl = new Template
+               tpl.add "<ul>"
+               for name in names do
+                       tpl.add "<li><b>{name.html_escape}</b></li>"
+               end
+               tpl.add "</ul>"
+               return tpl.write_to_string
+       end
+end
+
+redef class CmdIniLicense
+       redef fun to_html do
+               var license = self.license
+               if license == null then return ""
+
+               return "<a href=\"https://opensource.org/licenses/{license}\">{license}</a>"
+       end
+end
+
+redef class CmdEntityFile
+
+       # URL to the file
+       #
+       # Can be refined in subtools.
+       var file_url: nullable String = file is lazy, writable
+
+       redef fun to_html do
+               var file = self.file
+               if file == null then return ""
+
+               return "<a href=\"{file_url or else ""}\">{file.basename}</a>"
+       end
+end
+
+redef class CmdEntityFileContent
+       redef fun to_html do
+               var content = self.content
+               if content == null then return ""
+
+               return "<pre>{content}</pre>"
+       end
+end
index fefb1c7..8649179 100644 (file)
@@ -129,4 +129,76 @@ class TestCommandsHtml
                cmd.init_command
                print_html cmd.to_html
        end
+
+       # CmdIni
+
+       fun test_cmd_ini_desc is test do
+               var cmd = new CmdIniDescription(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_git is test do
+               var cmd = new CmdIniGitUrl(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_clone is test do
+               var cmd = new CmdIniCloneCommand(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_issues is test do
+               var cmd = new CmdIniIssuesUrl(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_maintainer is test do
+               var cmd = new CmdIniMaintainer(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_contributors is test do
+               var cmd = new CmdIniContributors(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_license is test do
+               var cmd = new CmdIniLicense(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_license_file is test do
+               var cmd = new CmdLicenseFile(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               cmd.file = cmd.file.as(not null).basename # for testing path
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_license_file_content is test do
+               var cmd = new CmdLicenseFileContent(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               cmd.file = cmd.file.as(not null).basename # for testing path
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_contrib_file is test do
+               var cmd = new CmdContribFile(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               cmd.file = cmd.file.as(not null).basename # for testing path
+               print_html cmd.to_html
+       end
+
+       fun test_cmd_ini_contrib_file_content is test do
+               var cmd = new CmdContribFileContent(test_view, mentity_name = "test_prog")
+               cmd.init_command
+               cmd.file = cmd.file.as(not null).basename # for testing path
+               print_html cmd.to_html
+       end
 end
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_clone.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_clone.res
new file mode 100644 (file)
index 0000000..10b2095
--- /dev/null
@@ -0,0 +1 @@
+<pre>git clone https://github.com/nitlang/nit.git</pre>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file.res
new file mode 100644 (file)
index 0000000..f5a98d5
--- /dev/null
@@ -0,0 +1 @@
+<a href="CONTRIBUTING.md">CONTRIBUTING.md</a>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file_content.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file_content.res
new file mode 100644 (file)
index 0000000..263fd6e
--- /dev/null
@@ -0,0 +1,6 @@
+<pre># Contributing rules
+
+* Be nice
+* Be polite
+* Code well
+</pre>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contributors.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contributors.res
new file mode 100644 (file)
index 0000000..b7d0788
--- /dev/null
@@ -0,0 +1 @@
+<ul><li><b>Riri &lt;riri@example.com&gt;</b></li><li><b>Fifi (http:&#47;&#47;www.example.com&#47;~fifi)</b></li><li><b>Loulou</b></li></ul>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_desc.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_desc.res
new file mode 100644 (file)
index 0000000..9d0fc44
--- /dev/null
@@ -0,0 +1 @@
+<p>Dummy program used for testing Nit tools</p>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_git.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_git.res
new file mode 100644 (file)
index 0000000..eea5e14
--- /dev/null
@@ -0,0 +1 @@
+<a href="https://github.com/nitlang/nit.git">https://github.com/nitlang/nit.git</a>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_issues.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_issues.res
new file mode 100644 (file)
index 0000000..d8061a2
--- /dev/null
@@ -0,0 +1 @@
+<a href="https://github.com/nitlang/nit/issues">https://github.com/nitlang/nit/issues</a>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license.res
new file mode 100644 (file)
index 0000000..ad3fca1
--- /dev/null
@@ -0,0 +1 @@
+<a href="https://opensource.org/licenses/Apache-2.0">Apache-2.0</a>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file.res
new file mode 100644 (file)
index 0000000..a8582ab
--- /dev/null
@@ -0,0 +1 @@
+<a href="LICENSE.md">LICENSE.md</a>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file_content.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file_content.res
new file mode 100644 (file)
index 0000000..3e31799
--- /dev/null
@@ -0,0 +1,4 @@
+<pre># My Custom License
+
+This is the license content.
+</pre>
diff --git a/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_maintainer.res b/src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_maintainer.res
new file mode 100644 (file)
index 0000000..bef5956
--- /dev/null
@@ -0,0 +1 @@
+<b>John Doe &lt;jdoe@example.com&gt; (http:&#47;&#47;www.example.com&#47;~jdoe), Spider-Man</b>