doc/commands: introduce html rendering for commands
[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
21 import templates::templates_html
22 import doc_down
23 import highlight
24
25 redef class DocCommand
26
27 # Render results as a HTML string
28 fun to_html: Writable do return "<p class='text-danger'>Not yet implemented</p>"
29 end
30
31 redef class CmdMessage
32
33 # Render the message as a HTML string
34 fun to_html: Writable is abstract
35 end
36
37 redef class CmdError
38 redef fun to_html do return "<p class='text-danger'>Error: {to_s}</p>"
39 end
40
41 redef class CmdWarning
42 redef fun to_html do return "<p class='text-warning'>Warning: {to_s}</p>"
43 end
44
45 # Model commands
46
47 redef class CmdEntity
48 redef fun to_html do
49 var mentity = self.mentity
50 if mentity == null then return ""
51 return mentity.html_link
52 end
53 end
54
55 redef class CmdEntities
56 redef fun to_html do
57 var mentities = self.results
58 if mentities == null then return ""
59
60 var tpl = new Template
61 tpl.add "<ul>"
62 for mentity in mentities do
63 var mdoc = mentity.mdoc_or_fallback
64 tpl.add "<li>"
65 tpl.add mentity.html_link
66 if mdoc != null then
67 tpl.add " - "
68 tpl.add mdoc.html_synopsis
69 end
70 tpl.add "</li>"
71 end
72 tpl.add "</ul>"
73 return tpl.write_to_string
74 end
75 end
76
77 redef class CmdComment
78 redef fun to_html do
79 var mentity = self.mentity
80 if mentity == null then return ""
81
82 var mdoc = self.mdoc
83 var tpl = new Template
84 tpl.add "<h3>"
85 # FIXME comments left here until I figure out what to do about the presentation options
86 # if not opts.has_key("no-link") then
87 tpl.add mentity.html_link
88 # end
89 if mdoc != null then
90 # if not opts.has_key("no-link") and not opts.has_key("no-synopsis") then
91 tpl.add " - "
92 # end
93 # if not opts.has_key("no-synopsis") then
94 tpl.add mdoc.html_synopsis
95 # end
96 end
97 tpl.add "</h3>"
98 if mdoc != null then
99 # if not opts.has_key("no-comment") then
100 tpl.add mdoc.html_comment
101 # end
102 end
103 return tpl.write_to_string
104 end
105 end
106
107 redef class CmdCode
108 redef fun to_html do
109 var output = render
110 if output == null then return ""
111 return "<pre>{output.write_to_string}</pre>"
112 end
113 end
114
115 # Graph commands
116
117 redef class CmdGraph
118 redef fun to_html do
119 var output = render
120 if output == null then return ""
121 return output.write_to_string
122 end
123 end