82571cc9ec9e7e65e3b82a4ec1ebbefc02bc785f
[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::commands_model
19 import commands::commands_graph
20 import commands::commands_usage
21 import commands::commands_catalog
22 import commands::commands_ini
23
24 import templates::templates_json
25 import catalog::catalog_json
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 CmdEntityCode
89 redef fun to_json do
90 var obj = new JsonObject
91 var node = self.node
92 if node != null then
93 obj["location"] = node.location
94 end
95 var output = render_code(node)
96 if output != null then
97 obj["code"] = output.write_to_string
98 end
99 return obj
100 end
101 end
102
103 redef class CmdGraph
104 redef fun to_json do
105 var obj = new JsonObject
106 var output = render
107 if output != null then
108 obj["graph"] = output.write_to_string
109 end
110 return obj
111 end
112 end
113
114 redef class CmdMetadata
115 redef fun to_json do return metadata
116 end
117
118 # CmdCatalog
119
120 redef class CmdCatalogStats
121 redef fun to_json do return stats
122 end
123
124 redef class CmdCatalogTags
125 redef fun to_json do return packages_count_by_tags
126 end
127
128 redef class CmdCatalogTag
129 redef fun to_json do
130 var obj = super.as(JsonObject)
131 obj["tag"] = tag
132 return obj
133 end
134 end
135
136 redef class CmdCatalogPerson
137 redef fun to_json do return person
138 end
139
140 redef class CmdCatalogMaintaining
141 redef fun to_json do
142 var obj = new JsonObject
143 obj["person"] = person
144 obj["results"] = results
145 obj["page"] = page
146 obj["count"] = count
147 obj["limit"] = limit
148 obj["max"] = max
149 return obj
150 end
151 end
152
153 redef class CmdCatalogContributing
154 redef fun to_json do
155 var obj = new JsonObject
156 obj["person"] = person
157 obj["results"] = results
158 obj["page"] = page
159 obj["count"] = count
160 obj["limit"] = limit
161 obj["max"] = max
162 return obj
163 end
164 end
165
166 # CmdIni
167
168 redef class CmdIniDescription
169 redef fun to_json do
170 var obj = new JsonObject
171 obj["desc"] = desc
172 return obj
173 end
174 end
175
176 redef class CmdIniGitUrl
177 redef fun to_json do
178 var obj = new JsonObject
179 obj["url"] = url
180 return obj
181 end
182 end
183
184 redef class CmdIniCloneCommand
185 redef fun to_json do
186 var obj = new JsonObject
187 obj["command"] = command
188 return obj
189 end
190 end
191
192 redef class CmdIniIssuesUrl
193 redef fun to_json do
194 var obj = new JsonObject
195 obj["url"] = url
196 return obj
197 end
198 end
199
200 redef class CmdIniMaintainer
201 redef fun to_json do
202 var obj = new JsonObject
203 obj["maintainer"] = maintainer
204 return obj
205 end
206 end
207
208 redef class CmdIniContributors
209 redef fun to_json do
210 var obj = new JsonObject
211 obj["contributors"] = contributors
212 return obj
213 end
214 end
215
216 redef class CmdIniLicense
217 redef fun to_json do
218 var obj = new JsonObject
219 obj["license"] = license
220 return obj
221 end
222 end
223
224 redef class CmdLicenseFile
225 redef fun to_json do
226 var obj = new JsonObject
227 obj["file"] = file
228 return obj
229 end
230 end
231
232 redef class CmdLicenseFileContent
233 redef fun to_json do
234 var obj = super.as(JsonObject)
235 obj["content"] = content
236 return obj
237 end
238 end
239
240 redef class CmdContribFile
241 redef fun to_json do
242 var obj = new JsonObject
243 obj["file"] = file
244 return obj
245 end
246 end
247
248 redef class CmdContribFileContent
249 redef fun to_json do
250 var obj = super.as(JsonObject)
251 obj["content"] = content
252 return obj
253 end
254 end