56d0e5b320324431ea51d362322160931d2b175c
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_catalog
24 import templates
::templates_html
28 redef class DocCommand
30 # Render results as a HTML string
31 fun to_html
: Writable do return "<p class='text-danger'>Not yet implemented</p>"
34 redef class CmdMessage
36 # Render the message as a HTML string
37 fun to_html
: Writable is abstract
41 redef fun to_html
do return "<p class='text-danger'>Error: {to_s}</p>"
44 redef class CmdWarning
45 redef fun to_html
do return "<p class='text-warning'>Warning: {to_s}</p>"
52 var mentity
= self.mentity
53 if mentity
== null then return ""
54 return mentity
.html_link
.write_to_string
58 redef class CmdEntities
60 var mentities
= self.results
61 if mentities
== null then return ""
63 var tpl
= new Template
65 for mentity
in mentities
do
66 var mdoc
= mentity
.mdoc_or_fallback
68 tpl
.add mentity
.html_link
71 tpl
.add mdoc
.html_synopsis
76 return tpl
.write_to_string
80 redef class CmdComment
82 var mentity
= self.mentity
83 if mentity
== null then return ""
86 var tpl
= new Template
88 # FIXME comments left here until I figure out what to do about the presentation options
89 # if not opts.has_key("no-link") then
90 tpl
.add mentity
.html_link
93 # if not opts.has_key("no-link") and not opts.has_key("no-synopsis") then
96 # if not opts.has_key("no-synopsis") then
97 tpl
.add mdoc
.html_synopsis
102 # if not opts.has_key("no-comment") then
103 tpl
.add mdoc
.html_comment
106 return tpl
.write_to_string
109 redef fun render_comment
do
111 if mdoc
== null then return null
113 if format
== "html" then
114 if full_doc
then return mdoc
.html_documentation
115 return mdoc
.html_synopsis
121 redef class CmdEntityLink
123 var mentity
= self.mentity
124 if mentity
== null then return ""
125 return mentity
.html_link
(text
, title
).write_to_string
132 if node
== null then return ""
134 var code
= render_code
(node
)
135 return "<pre>{code.write_to_string}</pre>"
138 redef fun render_code
(node
) do
139 if format
== "html" then
140 var hl
= new CmdHtmlightVisitor
141 hl
.show_infobox
= false
142 hl
.highlight_node node
149 # Custom HtmlightVisitor for commands
151 # We create a new subclass so its behavior can be refined in clients without
152 # breaking the main implementation.
153 class CmdHtmlightVisitor
154 super HtmlightVisitor
156 redef fun hrefto
(mentity
) do
157 if mentity
isa MClassDef then return mentity
.mclass
.html_url
158 if mentity
isa MPropDef then return mentity
.mproperty
.html_url
159 return mentity
.html_url
163 redef class CmdAncestors
164 redef fun to_html
do return super # FIXME lin
167 redef class CmdParents
168 redef fun to_html
do return super # FIXME lin
171 redef class CmdChildren
172 redef fun to_html
do return super # FIXME lin
175 redef class CmdDescendants
176 redef fun to_html
do return super # FIXME lin
179 redef class CmdFeatures
180 redef fun to_html
do return super # FIXME lin
183 redef class CmdLinearization
184 redef fun to_html
do return super # FIXME lin
190 redef fun to_html
do return super # FIXME lin
194 redef fun to_html
do return super # FIXME lin
197 redef class CmdReturn
198 redef fun to_html
do return super # FIXME lin
202 redef fun to_html
do return super # FIXME lin
210 if output
== null then return ""
211 return output
.write_to_string
217 redef class CmdIniDescription
220 if desc
== null then return ""
222 return "<p>{desc}</p>"
226 redef class CmdIniGitUrl
229 if url
== null then return ""
231 return "<a href=\"{url}\
">{url}</a>"
235 redef class CmdIniCloneCommand
237 var command
= self.command
238 if command
== null then return ""
240 return "<pre>{command}</pre>"
244 redef class CmdIniIssuesUrl
247 if url
== null then return ""
249 return "<a href=\"{url}\
">{url}</a>"
253 redef class CmdIniMaintainer
255 var name
= self.maintainer
256 if name
== null then return ""
258 return "<b>{name.html_escape}</b>"
262 redef class CmdIniContributors
264 var names
= self.contributors
265 if names
== null or names
.is_empty
then return ""
267 var tpl
= new Template
270 tpl
.add
"<li><b>{name.html_escape}</b></li>"
273 return tpl
.write_to_string
277 redef class CmdIniLicense
279 var license
= self.license
280 if license
== null then return ""
282 return "<a href=\"https
://opensource
.org
/licenses
/{license}\
">{license}</a>"
286 redef class CmdEntityFile
290 # Can be refined in subtools.
291 var file_url
: nullable String = file
is lazy
, writable
295 if file
== null then return ""
297 return "<a href=\"{file_url or else ""}\
">{file.basename}</a>"
301 redef class CmdEntityFileContent
303 var content
= self.content
304 if content
== null then return ""
306 return "<pre>{content}</pre>"
313 redef fun to_html
do return super # FIXME lin
316 redef class CmdMainCompile
318 var command
= self.command
319 if command
== null then return ""
321 return "<pre>{command}</pre>"
325 redef class CmdManSynopsis
327 var synopsis
= self.synopsis
328 if synopsis
== null then return ""
330 return "<pre>{synopsis}</pre>"
334 redef class CmdManOptions
336 var options
= self.options
337 if options
== null or options
.is_empty
then return ""
339 var tpl
= new Template
341 tpl
.addn
"<table width='100%'>"
342 for opt
, desc
in options
do
344 tpl
.addn
"<th valign='top' width='30%'>{opt}</th>"
345 tpl
.addn
"<td width='70%'>{desc}</td>"
351 return tpl
.write_to_string
355 redef class CmdTesting
357 var command
= self.command
358 if command
== null then return ""
360 return "<pre>{command}</pre>"