7aac39ab2d5a71499ba0fda499d5da2af05c2323
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 HTML
18 import commands
::commands_graph
19 import commands
::commands_usage
20 import commands
::commands_ini
21 import commands
::commands_main
23 import templates
::templates_html
27 redef class DocCommand
29 # Render results as a HTML string
30 fun to_html
: Writable do return "<p class='text-danger'>Not yet implemented</p>"
33 redef class CmdMessage
35 # Render the message as a HTML string
36 fun to_html
: Writable is abstract
40 redef fun to_html
do return "<p class='text-danger'>Error: {to_s}</p>"
43 redef class CmdWarning
44 redef fun to_html
do return "<p class='text-warning'>Warning: {to_s}</p>"
51 var mentity
= self.mentity
52 if mentity
== null then return ""
53 return mentity
.html_link
.write_to_string
57 redef class CmdEntities
59 var mentities
= self.results
60 if mentities
== null then return ""
62 var tpl
= new Template
64 for mentity
in mentities
do
65 var mdoc
= mentity
.mdoc_or_fallback
67 tpl
.add mentity
.html_link
70 tpl
.add mdoc
.html_synopsis
75 return tpl
.write_to_string
79 redef class CmdComment
81 var mentity
= self.mentity
82 if mentity
== null then return ""
85 var tpl
= new Template
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
92 # if not opts.has_key("no-link") and not opts.has_key("no-synopsis") then
95 # if not opts.has_key("no-synopsis") then
96 tpl
.add mdoc
.html_synopsis
101 # if not opts.has_key("no-comment") then
102 tpl
.add mdoc
.html_comment
105 return tpl
.write_to_string
109 redef class CmdEntityLink
111 var mentity
= self.mentity
112 if mentity
== null then return ""
113 return mentity
.html_link
(text
, title
).write_to_string
117 redef class CmdEntityCode
119 var output
= render_code
(node
)
120 if output
== null then return ""
121 return "<pre>{output.write_to_string}</pre>"
125 redef class CmdAncestors
126 redef fun to_html
do return super # FIXME lin
129 redef class CmdParents
130 redef fun to_html
do return super # FIXME lin
133 redef class CmdChildren
134 redef fun to_html
do return super # FIXME lin
137 redef class CmdDescendants
138 redef fun to_html
do return super # FIXME lin
141 redef class CmdFeatures
142 redef fun to_html
do return super # FIXME lin
145 redef class CmdLinearization
146 redef fun to_html
do return super # FIXME lin
152 redef fun to_html
do return super # FIXME lin
156 redef fun to_html
do return super # FIXME lin
159 redef class CmdReturn
160 redef fun to_html
do return super # FIXME lin
164 redef fun to_html
do return super # FIXME lin
172 if output
== null then return ""
173 return output
.write_to_string
179 redef class CmdIniDescription
182 if desc
== null then return ""
184 return "<p>{desc}</p>"
188 redef class CmdIniGitUrl
191 if url
== null then return ""
193 return "<a href=\"{url}\
">{url}</a>"
197 redef class CmdIniCloneCommand
199 var command
= self.command
200 if command
== null then return ""
202 return "<pre>{command}</pre>"
206 redef class CmdIniIssuesUrl
209 if url
== null then return ""
211 return "<a href=\"{url}\
">{url}</a>"
215 redef class CmdIniMaintainer
217 var name
= self.maintainer
218 if name
== null then return ""
220 return "<b>{name.html_escape}</b>"
224 redef class CmdIniContributors
226 var names
= self.contributors
227 if names
== null or names
.is_empty
then return ""
229 var tpl
= new Template
232 tpl
.add
"<li><b>{name.html_escape}</b></li>"
235 return tpl
.write_to_string
239 redef class CmdIniLicense
241 var license
= self.license
242 if license
== null then return ""
244 return "<a href=\"https
://opensource
.org
/licenses
/{license}\
">{license}</a>"
248 redef class CmdEntityFile
252 # Can be refined in subtools.
253 var file_url
: nullable String = file
is lazy
, writable
257 if file
== null then return ""
259 return "<a href=\"{file_url or else ""}\
">{file.basename}</a>"
263 redef class CmdEntityFileContent
265 var content
= self.content
266 if content
== null then return ""
268 return "<pre>{content}</pre>"
275 redef fun to_html
do return super # FIXME lin
278 redef class CmdMainCompile
280 var command
= self.command
281 if command
== null then return ""
283 return "<pre>{command}</pre>"
287 redef class CmdManSynopsis
289 var synopsis
= self.synopsis
290 if synopsis
== null then return ""
292 return "<pre>{synopsis}</pre>"
296 redef class CmdManOptions
298 var options
= self.options
299 if options
== null or options
.is_empty
then return ""
301 var tpl
= new Template
303 tpl
.addn
"<table width='100%'>"
304 for opt
, desc
in options
do
306 tpl
.addn
"<th valign='top' width='30%'>{opt}</th>"
307 tpl
.addn
"<td width='70%'>{desc}</td>"
313 return tpl
.write_to_string
317 redef class CmdTesting
319 var command
= self.command
320 if command
== null then return ""
322 return "<pre>{command}</pre>"
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