src/doc/commands: clean commands modules importation
[nit.git] / src / doc / commands / commands_md.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Render commands results as Markdown
16 module commands_md
17
18 import commands_catalog
19 import commands_graph
20 import commands_ini
21 import commands_main
22 import commands_usage
23
24 import doc_down
25
26 redef class DocCommand
27
28 # Render results as a Markdown string
29 fun to_md: Writable do return "**Not yet implemented**"
30 end
31
32 redef class CmdMessage
33
34 # Render the message as a HTML string
35 fun to_md: Writable is abstract
36 end
37
38 redef class CmdError
39 redef fun to_md do return "**Error: {to_s}**"
40 end
41
42 redef class CmdWarning
43 redef fun to_md do return "**Warning: {to_s}**"
44 end
45
46 # Model commands
47
48 redef class CmdEntity
49 redef fun to_md do
50 var mentity = self.mentity
51 if mentity == null then return ""
52 return "`{mentity.name}`"
53 end
54 end
55
56 redef class CmdEntities
57 redef fun to_md do
58 var mentities = self.results
59 if mentities == null then return ""
60
61 var tpl = new Template
62 for mentity in mentities do
63 var mdoc = mentity.mdoc_or_fallback
64 tpl.add "* `{mentity}`"
65 if mdoc != null then
66 tpl.add " - "
67 tpl.add mdoc.synopsis
68 end
69 tpl.add "\n"
70 end
71 return tpl.write_to_string
72 end
73 end
74
75 redef class CmdComment
76 redef fun to_md do
77 var mentity = self.mentity
78 if mentity == null then return ""
79
80 var mdoc = self.mdoc
81 var tpl = new Template
82 tpl.add "### `{mentity}`"
83 if mdoc != null then
84 tpl.add " - "
85 tpl.add mdoc.synopsis
86 end
87 tpl.add "\n"
88 if mdoc != null then
89 tpl.add mdoc.comment
90 end
91 return tpl.write_to_string
92 end
93
94 redef fun render_comment do
95 var mdoc = self.mdoc
96 if mdoc == null then return null
97
98 if format == "md" then
99 if full_doc then return mdoc.md_documentation
100 return mdoc.md_synopsis
101 end
102 return super
103 end
104 end
105
106 redef class CmdEntityLink
107 redef fun to_md do
108 var mentity = self.mentity
109 if mentity == null then return ""
110 return "`{mentity}`"
111 end
112 end
113
114 redef class CmdCode
115 redef fun to_md do
116 var node = self.node
117 if node == null then return ""
118
119 var code = render_code(node)
120 var tpl = new Template
121 tpl.addn "~~~nit"
122 tpl.add code.write_to_string
123 tpl.addn "~~~"
124 return tpl.write_to_string
125 end
126
127 redef fun render_code(node) do
128 if format == "ansi" then
129 var hl = new AnsiHighlightVisitor
130 hl.highlight_node node
131 return hl.result
132 end
133 return super
134 end
135 end
136
137 redef class CmdAncestors
138 redef fun to_md do return super # FIXME lin
139 end
140
141 redef class CmdParents
142 redef fun to_md do return super # FIXME lin
143 end
144
145 redef class CmdChildren
146 redef fun to_md do return super # FIXME lin
147 end
148
149 redef class CmdDescendants
150 redef fun to_md do return super # FIXME lin
151 end
152
153 redef class CmdFeatures
154 redef fun to_md do return super # FIXME lin
155 end
156
157 redef class CmdLinearization
158 redef fun to_md do return super # FIXME lin
159 end
160
161 # Usage commands
162
163 redef class CmdNew
164 redef fun to_md do return super # FIXME lin
165 end
166
167 redef class CmdCall
168 redef fun to_md do return super # FIXME lin
169 end
170
171 redef class CmdReturn
172 redef fun to_md do return super # FIXME lin
173 end
174
175 redef class CmdParam
176 redef fun to_md do return super # FIXME lin
177 end
178
179 # Graph commands
180
181 redef class CmdGraph
182 redef fun to_md do
183 var output = render
184 if output == null then return ""
185 return output.write_to_string
186 end
187 end
188
189 # Ini commands
190
191 redef class CmdIniDescription
192 redef fun to_md do
193 var desc = self.desc
194 if desc == null then return ""
195
196 return desc
197 end
198 end
199
200 redef class CmdIniGitUrl
201 redef fun to_md do
202 var url = self.url
203 if url == null then return ""
204 return "[{url}]({url})"
205 end
206 end
207
208 redef class CmdIniCloneCommand
209 redef fun to_md do
210 var command = self.command
211 if command == null then return ""
212
213 var tpl = new Template
214 tpl.addn "~~~sh"
215 tpl.addn command
216 tpl.addn "~~~"
217 return tpl.write_to_string
218 end
219 end
220
221 redef class CmdIniIssuesUrl
222 redef fun to_md do
223 var url = self.url
224 if url == null then return ""
225 return "[{url}]({url})"
226 end
227 end
228
229 redef class CmdIniMaintainer
230 redef fun to_md do
231 var name = self.maintainer
232 if name == null then return ""
233 return "**{name}**"
234 end
235 end
236
237 redef class CmdIniContributors
238 redef fun to_md do
239 var names = self.contributors
240 if names == null or names.is_empty then return ""
241
242 var tpl = new Template
243 for name in names do
244 tpl.addn "* **{name}**"
245 end
246 return tpl.write_to_string
247 end
248 end
249
250 redef class CmdIniLicense
251 redef fun to_md do
252 var license = self.license
253 if license == null then return ""
254 return "[{license}](https://opensource.org/licenses/{license})"
255 end
256 end
257
258 redef class CmdEntityFile
259
260 # URL to the file
261 #
262 # Can be refined in subtools.
263 var file_url: nullable String = file is lazy, writable
264
265 redef fun to_md do
266 var file = self.file
267 if file == null then return ""
268 return "[{file.basename}]({file_url or else ""})"
269 end
270 end
271
272 redef class CmdEntityFileContent
273 redef fun to_md do
274 var content = self.content
275 if content == null then return ""
276
277 var tpl = new Template
278 tpl.addn "~~~"
279 tpl.add content
280 tpl.addn "~~~"
281 return tpl.write_to_string
282 end
283 end
284
285 # Main commands
286
287 redef class CmdMains
288 redef fun to_md do return super # FIXME lin
289 end
290
291 redef class CmdMainCompile
292 redef fun to_md do
293 var command = self.command
294 if command == null then return ""
295
296 var tpl = new Template
297 tpl.addn "~~~sh"
298 tpl.addn command
299 tpl.addn "~~~"
300 return tpl.write_to_string
301 end
302 end
303
304 redef class CmdManSynopsis
305 redef fun to_md do
306 var synopsis = self.synopsis
307 if synopsis == null then return ""
308
309 var tpl = new Template
310 tpl.addn "~~~"
311 tpl.addn synopsis
312 tpl.addn "~~~"
313 return tpl.write_to_string
314 end
315 end
316
317 redef class CmdManOptions
318 redef fun to_md do
319 var options = self.options
320 if options == null or options.is_empty then return ""
321
322 var tpl = new Template
323 tpl.addn "~~~"
324 for opt, desc in options do
325 tpl.addn "* {opt}\t\t{desc}"
326 end
327 tpl.addn "~~~"
328
329 return tpl.write_to_string
330 end
331 end
332
333 redef class CmdTesting
334 redef fun to_md do
335 var command = self.command
336 if command == null then return ""
337
338 var tpl = new Template
339 tpl.addn "~~~sh"
340 tpl.addn command
341 tpl.addn "~~~"
342 return tpl.write_to_string
343 end
344 end