77ad14a02c94bca7197a2cf38c5bebc574e5fb58
1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Render commands results as Markdown
18 import commands
::commands_graph
19 import commands
::commands_usage
20 import commands
::commands_ini
21 import commands
::commands_main
25 redef class DocCommand
27 # Render results as a Markdown string
28 fun to_md
: Writable do return "**Not yet implemented**"
31 redef class CmdMessage
33 # Render the message as a HTML string
34 fun to_md
: Writable is abstract
38 redef fun to_md
do return "**Error: {to_s}**"
41 redef class CmdWarning
42 redef fun to_md
do return "**Warning: {to_s}**"
49 var mentity
= self.mentity
50 if mentity
== null then return ""
51 return "`{mentity.name}`"
55 redef class CmdEntities
57 var mentities
= self.results
58 if mentities
== null then return ""
60 var tpl
= new Template
61 for mentity
in mentities
do
62 var mdoc
= mentity
.mdoc_or_fallback
63 tpl
.add
"* `{mentity}`"
70 return tpl
.write_to_string
74 redef class CmdComment
76 var mentity
= self.mentity
77 if mentity
== null then return ""
80 var tpl
= new Template
81 tpl
.add
"### `{mentity}`"
90 return tpl
.write_to_string
94 redef class CmdEntityLink
96 var mentity
= self.mentity
97 if mentity
== null then return ""
102 redef class CmdEntityCode
104 var output
= render_code
(node
)
105 if output
== null then return ""
107 var tpl
= new Template
109 tpl
.add output
.write_to_string
111 return tpl
.write_to_string
115 redef class CmdAncestors
116 redef fun to_md
do return super # FIXME lin
119 redef class CmdParents
120 redef fun to_md
do return super # FIXME lin
123 redef class CmdChildren
124 redef fun to_md
do return super # FIXME lin
127 redef class CmdDescendants
128 redef fun to_md
do return super # FIXME lin
131 redef class CmdFeatures
132 redef fun to_md
do return super # FIXME lin
135 redef class CmdLinearization
136 redef fun to_md
do return super # FIXME lin
142 redef fun to_md
do return super # FIXME lin
146 redef fun to_md
do return super # FIXME lin
149 redef class CmdReturn
150 redef fun to_md
do return super # FIXME lin
154 redef fun to_md
do return super # FIXME lin
162 if output
== null then return ""
163 return output
.write_to_string
169 redef class CmdIniDescription
172 if desc
== null then return ""
178 redef class CmdIniGitUrl
181 if url
== null then return ""
182 return "[{url}]({url})"
186 redef class CmdIniCloneCommand
188 var command
= self.command
189 if command
== null then return ""
191 var tpl
= new Template
195 return tpl
.write_to_string
199 redef class CmdIniIssuesUrl
202 if url
== null then return ""
203 return "[{url}]({url})"
207 redef class CmdIniMaintainer
209 var name
= self.maintainer
210 if name
== null then return ""
215 redef class CmdIniContributors
217 var names
= self.contributors
218 if names
== null or names
.is_empty
then return ""
220 var tpl
= new Template
222 tpl
.addn
"* **{name}**"
224 return tpl
.write_to_string
228 redef class CmdIniLicense
230 var license
= self.license
231 if license
== null then return ""
232 return "[{license}](https://opensource.org/licenses/{license})"
236 redef class CmdEntityFile
240 # Can be refined in subtools.
241 var file_url
: nullable String = file
is lazy
, writable
245 if file
== null then return ""
246 return "[{file.basename}]({file_url or else ""})"
250 redef class CmdEntityFileContent
252 var content
= self.content
253 if content
== null then return ""
255 var tpl
= new Template
259 return tpl
.write_to_string
266 redef fun to_md
do return super # FIXME lin
269 redef class CmdMainCompile
271 var command
= self.command
272 if command
== null then return ""
274 var tpl
= new Template
278 return tpl
.write_to_string
282 redef class CmdManSynopsis
284 var synopsis
= self.synopsis
285 if synopsis
== null then return ""
287 var tpl
= new Template
291 return tpl
.write_to_string
295 redef class CmdManOptions
297 var options
= self.options
298 if options
== null or options
.is_empty
then return ""
300 var tpl
= new Template
302 for opt
, desc
in options
do
303 tpl
.addn
"* {opt}\t\t{desc}"
307 return tpl
.write_to_string
311 redef class CmdTesting
313 var command
= self.command
314 if command
== null then return ""
316 var tpl
= new Template
320 return tpl
.write_to_string