src/doc/commands/templates: move `commands_html` to `html_commands`
[nit.git] / src / doc / commands / commands_json.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 # Translate command results to json
16 module commands_json
17
18 import commands_catalog
19 import commands_graph
20 import commands_ini
21 import commands_main
22 import commands_usage
23
24 import templates::json_model
25 import json::static
26
27 redef class DocCommand
28 # Return a JSON Serializable representation of `self` results
29 fun to_json: nullable Serializable is abstract
30 end
31
32 # Message handling
33
34 redef class CmdMessage
35 # Return a JSON Serializable representation of `self`
36 fun to_json: nullable Serializable do
37 var obj = new JsonObject
38 obj["status"] = class_name
39 obj["message"] = to_s
40 return obj
41 end
42 end
43
44 redef class CmdEntity
45 redef fun to_json do return mentity
46 end
47
48 redef class CmdList
49 redef fun to_json do
50 var obj = new JsonObject
51 obj["results"] = results
52 obj["page"] = page
53 obj["count"] = count
54 obj["limit"] = limit
55 obj["max"] = max
56 return obj
57 end
58 end
59
60 redef class CmdEntityList
61 redef fun to_json do return super
62 end
63
64 # Model commands
65
66 redef class CmdComment
67 redef fun to_json do
68 var obj = new JsonObject
69 var render = self.render_comment
70 if render != null then
71 obj["documentation"] = render.write_to_string
72 end
73 return obj
74 end
75 end
76
77 redef class CmdEntityLink
78 redef fun to_json do
79 var obj = new JsonObject
80 var text = self.text
81 if text != null then obj["text"] = text
82 var title = self.title
83 if title != null then obj["title"] = title
84 return obj
85 end
86 end
87
88 redef class CmdCode
89 redef fun to_json do
90 var obj = new JsonObject
91 var node = self.node
92 if node == null then return obj
93
94 var code = render_code(node)
95 obj["location"] = node.location
96 obj["code"] = code.write_to_string
97 return obj
98 end
99 end
100
101 redef class CmdGraph
102 redef fun to_json do
103 var obj = new JsonObject
104 var output = render
105 if output != null then
106 obj["graph"] = output.write_to_string
107 end
108 return obj
109 end
110 end
111
112 redef class CmdMetadata
113 redef fun to_json do return metadata
114 end
115
116 # CmdCatalog
117
118 redef class CmdCatalogStats
119 redef fun to_json do return stats
120 end
121
122 redef class CmdCatalogTags
123 redef fun to_json do return packages_count_by_tags
124 end
125
126 redef class CmdCatalogTag
127 redef fun to_json do
128 var obj = super.as(JsonObject)
129 obj["tag"] = tag
130 return obj
131 end
132 end
133
134 redef class CmdCatalogPerson
135 redef fun to_json do return person
136 end
137
138 redef class CmdCatalogMaintaining
139 redef fun to_json do
140 var obj = new JsonObject
141 obj["person"] = person
142 obj["results"] = results
143 obj["page"] = page
144 obj["count"] = count
145 obj["limit"] = limit
146 obj["max"] = max
147 return obj
148 end
149 end
150
151 redef class CmdCatalogContributing
152 redef fun to_json do
153 var obj = new JsonObject
154 obj["person"] = person
155 obj["results"] = results
156 obj["page"] = page
157 obj["count"] = count
158 obj["limit"] = limit
159 obj["max"] = max
160 return obj
161 end
162 end
163
164 # CmdIni
165
166 redef class CmdIniDescription
167 redef fun to_json do
168 var obj = new JsonObject
169 obj["desc"] = desc
170 return obj
171 end
172 end
173
174 redef class CmdIniGitUrl
175 redef fun to_json do
176 var obj = new JsonObject
177 obj["url"] = url
178 return obj
179 end
180 end
181
182 redef class CmdIniCloneCommand
183 redef fun to_json do
184 var obj = new JsonObject
185 obj["command"] = command
186 return obj
187 end
188 end
189
190 redef class CmdIniIssuesUrl
191 redef fun to_json do
192 var obj = new JsonObject
193 obj["url"] = url
194 return obj
195 end
196 end
197
198 redef class CmdIniMaintainer
199 redef fun to_json do
200 var obj = new JsonObject
201 obj["maintainer"] = maintainer
202 return obj
203 end
204 end
205
206 redef class CmdIniContributors
207 redef fun to_json do
208 var obj = new JsonObject
209 obj["contributors"] = contributors
210 return obj
211 end
212 end
213
214 redef class CmdIniLicense
215 redef fun to_json do
216 var obj = new JsonObject
217 obj["license"] = license
218 return obj
219 end
220 end
221
222 redef class CmdLicenseFile
223 redef fun to_json do
224 var obj = new JsonObject
225 obj["file"] = file
226 return obj
227 end
228 end
229
230 redef class CmdLicenseFileContent
231 redef fun to_json do
232 var obj = super.as(JsonObject)
233 obj["content"] = content
234 return obj
235 end
236 end
237
238 redef class CmdContribFile
239 redef fun to_json do
240 var obj = new JsonObject
241 obj["file"] = file
242 return obj
243 end
244 end
245
246 redef class CmdContribFileContent
247 redef fun to_json do
248 var obj = super.as(JsonObject)
249 obj["content"] = content
250 return obj
251 end
252 end
253
254 # CmdMain
255
256 redef class CmdMains
257 redef fun to_json do
258 var obj = new JsonObject
259 obj["results"] = results
260 return obj
261 end
262 end
263
264 redef class CmdMainCompile
265 redef fun to_json do
266 var obj = new JsonObject
267 obj["command"] = command
268 return obj
269 end
270 end
271
272 redef class CmdTesting
273 redef fun to_json do
274 var obj = new JsonObject
275 obj["command"] = command
276 return obj
277 end
278 end
279
280 redef class CmdManSynopsis
281 redef fun to_json do
282 var obj = new JsonObject
283 obj["synopsis"] = synopsis
284 return obj
285 end
286 end
287
288 redef class CmdManOptions
289 redef fun to_json do
290 var obj = new JsonObject
291 obj["options"] = options
292 return obj
293 end
294 end