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