OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import copy | 5 import copy |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 | 8 |
9 from docs_server_utils import GetLinkToRefType | 9 from docs_server_utils import GetLinkToRefType |
10 import third_party.json_schema_compiler.model as model | 10 import third_party.json_schema_compiler.model as model |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 ref, rest = parts | 60 ref, rest = parts |
61 rest = ' ' + rest | 61 rest = ' ' + rest |
62 if not ref[-1].isalnum(): | 62 if not ref[-1].isalnum(): |
63 rest = ref[-1] + rest | 63 rest = ref[-1] + rest |
64 ref = ref[:-1] | 64 ref = ref[:-1] |
65 ref_dict = GetLinkToRefType(self._namespace.name, ref) | 65 ref_dict = GetLinkToRefType(self._namespace.name, ref) |
66 formatted_description.append('<a href="%(href)s">%(text)s</a>%(rest)s' % | 66 formatted_description.append('<a href="%(href)s">%(text)s</a>%(rest)s' % |
67 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest }) | 67 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest }) |
68 return ''.join(formatted_description) | 68 return ''.join(formatted_description) |
69 | 69 |
70 def Generate(self, samples): | 70 def Generate(self): |
71 try: | 71 try: |
72 return { | 72 return { |
73 'name': self._namespace.name, | 73 'name': self._namespace.name, |
74 'types': map(self._GenerateType, self._namespace.types.values()), | 74 'types': map(self._GenerateType, self._namespace.types.values()), |
75 'functions': self._GenerateFunctions(self._namespace.functions), | 75 'functions': self._GenerateFunctions(self._namespace.functions), |
76 'events': map(self._GenerateEvent, self._namespace.events.values()), | 76 'events': map(self._GenerateEvent, self._namespace.events.values()), |
77 'properties': self._GenerateProperties(self._namespace.properties), | 77 'properties': self._GenerateProperties(self._namespace.properties) |
78 'samples': samples, | |
79 } | 78 } |
80 except Exception as e: | 79 except Exception as e: |
81 logging.error(e) | 80 logging.error(e) |
82 raise | 81 raise |
83 | 82 |
84 def _GenerateType(self, type_): | 83 def _GenerateType(self, type_): |
85 type_dict = { | 84 type_dict = { |
86 'name': self._StripPrefix(type_.name), | 85 'name': self._StripPrefix(type_.name), |
87 'description': self._FormatDescription(type_.description), | 86 'description': self._FormatDescription(type_.description), |
88 'properties': self._GenerateProperties(type_.properties), | 87 'properties': self._GenerateProperties(type_.properties), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 elif property_.type_ == model.PropertyType.ENUM: | 176 elif property_.type_ == model.PropertyType.ENUM: |
178 dst_dict['enum_values'] = [] | 177 dst_dict['enum_values'] = [] |
179 for enum_value in property_.enum_values: | 178 for enum_value in property_.enum_values: |
180 dst_dict['enum_values'].append({'name': enum_value}) | 179 dst_dict['enum_values'].append({'name': enum_value}) |
181 if len(dst_dict['enum_values']) > 0: | 180 if len(dst_dict['enum_values']) > 0: |
182 dst_dict['enum_values'][-1]['last'] = True | 181 dst_dict['enum_values'][-1]['last'] = True |
183 elif property_.instance_of: | 182 elif property_.instance_of: |
184 dst_dict['simple_type'] = property_.instance_of.lower() | 183 dst_dict['simple_type'] = property_.instance_of.lower() |
185 else: | 184 else: |
186 dst_dict['simple_type'] = property_.type_.name.lower() | 185 dst_dict['simple_type'] = property_.type_.name.lower() |
OLD | NEW |