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