2670ebde9ab8f63761a4bac17a9f109f864af6ca
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
93 redef fun render_comment
do
95 if mdoc
== null then return null
97 if format
== "md" then
98 if full_doc
then return mdoc
.md_documentation
99 return mdoc
.md_synopsis
105 redef class CmdEntityLink
107 var mentity
= self.mentity
108 if mentity
== null then return ""
116 if node
== null then return ""
118 var code
= render_code
(node
)
119 var tpl
= new Template
121 tpl
.add code
.write_to_string
123 return tpl
.write_to_string
126 redef fun render_code
(node
) do
127 if format
== "ansi" then
128 var hl
= new AnsiHighlightVisitor
129 hl
.highlight_node node
136 redef class CmdAncestors
137 redef fun to_md
do return super # FIXME lin
140 redef class CmdParents
141 redef fun to_md
do return super # FIXME lin
144 redef class CmdChildren
145 redef fun to_md
do return super # FIXME lin
148 redef class CmdDescendants
149 redef fun to_md
do return super # FIXME lin
152 redef class CmdFeatures
153 redef fun to_md
do return super # FIXME lin
156 redef class CmdLinearization
157 redef fun to_md
do return super # FIXME lin
163 redef fun to_md
do return super # FIXME lin
167 redef fun to_md
do return super # FIXME lin
170 redef class CmdReturn
171 redef fun to_md
do return super # FIXME lin
175 redef fun to_md
do return super # FIXME lin
183 if output
== null then return ""
184 return output
.write_to_string
190 redef class CmdIniDescription
193 if desc
== null then return ""
199 redef class CmdIniGitUrl
202 if url
== null then return ""
203 return "[{url}]({url})"
207 redef class CmdIniCloneCommand
209 var command
= self.command
210 if command
== null then return ""
212 var tpl
= new Template
216 return tpl
.write_to_string
220 redef class CmdIniIssuesUrl
223 if url
== null then return ""
224 return "[{url}]({url})"
228 redef class CmdIniMaintainer
230 var name
= self.maintainer
231 if name
== null then return ""
236 redef class CmdIniContributors
238 var names
= self.contributors
239 if names
== null or names
.is_empty
then return ""
241 var tpl
= new Template
243 tpl
.addn
"* **{name}**"
245 return tpl
.write_to_string
249 redef class CmdIniLicense
251 var license
= self.license
252 if license
== null then return ""
253 return "[{license}](https://opensource.org/licenses/{license})"
257 redef class CmdEntityFile
261 # Can be refined in subtools.
262 var file_url
: nullable String = file
is lazy
, writable
266 if file
== null then return ""
267 return "[{file.basename}]({file_url or else ""})"
271 redef class CmdEntityFileContent
273 var content
= self.content
274 if content
== null then return ""
276 var tpl
= new Template
280 return tpl
.write_to_string
287 redef fun to_md
do return super # FIXME lin
290 redef class CmdMainCompile
292 var command
= self.command
293 if command
== null then return ""
295 var tpl
= new Template
299 return tpl
.write_to_string
303 redef class CmdManSynopsis
305 var synopsis
= self.synopsis
306 if synopsis
== null then return ""
308 var tpl
= new Template
312 return tpl
.write_to_string
316 redef class CmdManOptions
318 var options
= self.options
319 if options
== null or options
.is_empty
then return ""
321 var tpl
= new Template
323 for opt
, desc
in options
do
324 tpl
.addn
"* {opt}\t\t{desc}"
328 return tpl
.write_to_string
332 redef class CmdTesting
334 var command
= self.command
335 if command
== null then return ""
337 var tpl
= new Template
341 return tpl
.write_to_string