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 # Translate command results to json
18 import commands
::commands_model
19 import commands
::commands_graph
20 import commands
::commands_usage
21 import commands
::commands_catalog
23 import templates
::templates_json
24 import catalog
::catalog_json
26 redef class DocCommand
27 # Return a JSON Serializable representation of `self` results
28 fun to_json
: nullable Serializable is abstract
33 redef class CmdMessage
34 # Return a JSON Serializable representation of `self`
35 fun to_json
: nullable Serializable do
36 var obj
= new JsonObject
37 obj
["status"] = class_name
44 redef fun to_json
do return mentity
49 var obj
= new JsonObject
50 obj
["results"] = results
59 redef class CmdEntityList
60 redef fun to_json
do return super
65 redef class CmdComment
67 var obj
= new JsonObject
68 var render
= self.render_comment
69 if render
!= null then
70 obj
["documentation"] = render
.write_to_string
76 redef class CmdEntityLink
78 var obj
= new JsonObject
80 if text
!= null then obj
["text"] = text
81 var title
= self.title
82 if title
!= null then obj
["title"] = title
87 redef class CmdEntityCode
89 var obj
= new JsonObject
92 obj
["location"] = node
.location
94 var output
= render_code
(node
)
95 if output
!= null then
96 obj
["code"] = output
.write_to_string
104 var obj
= new JsonObject
106 if output
!= null then
107 obj
["graph"] = output
.write_to_string
113 redef class CmdMetadata
114 redef fun to_json
do return metadata
119 redef class CmdCatalogStats
120 redef fun to_json
do return stats
123 redef class CmdCatalogTags
124 redef fun to_json
do return packages_count_by_tags
127 redef class CmdCatalogTag
129 var obj
= super.as(JsonObject)
135 redef class CmdCatalogPerson
136 redef fun to_json
do return person
139 redef class CmdCatalogMaintaining
141 var obj
= new JsonObject
142 obj
["person"] = person
143 obj
["results"] = results
152 redef class CmdCatalogContributing
154 var obj
= new JsonObject
155 obj
["person"] = person
156 obj
["results"] = results