Chromium Code Reviews| 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 os | 6 import os |
| 7 | 7 |
| 8 import third_party.json_schema_compiler.model as model | 8 import third_party.json_schema_compiler.model as model |
| 9 | 9 |
| 10 def _RemoveNoDocs(item): | 10 def _RemoveNoDocs(item): |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 """ | 39 """ |
| 40 def __init__(self, json): | 40 def __init__(self, json): |
| 41 clean_json = copy.deepcopy(json) | 41 clean_json = copy.deepcopy(json) |
| 42 _RemoveNoDocs(clean_json) | 42 _RemoveNoDocs(clean_json) |
| 43 self._namespace = model.Namespace(clean_json, clean_json['namespace']) | 43 self._namespace = model.Namespace(clean_json, clean_json['namespace']) |
| 44 | 44 |
| 45 def Generate(self): | 45 def Generate(self): |
| 46 return { | 46 return { |
| 47 'name': self._namespace.name, | 47 'name': self._namespace.name, |
| 48 'types': self._GenerateTypes(self._namespace.types), | 48 'types': self._GenerateTypes(self._namespace.types), |
| 49 'functions': self._GenerateFunctions(self._namespace.functions) | 49 'functions': self._GenerateFunctions(self._namespace.functions), |
| 50 'properties': self._GenerateProperties(self._namespace.properties) | |
| 50 } | 51 } |
| 51 | 52 |
| 52 def _GenerateTypes(self, types): | 53 def _GenerateTypes(self, types): |
| 53 types_list = [] | 54 types_list = [] |
| 54 for type_name in types: | 55 for type_name in types: |
| 55 types_list.append(self._GenerateType(types[type_name])) | 56 types_list.append(self._GenerateType(types[type_name])) |
| 56 return types_list | 57 return types_list |
| 57 | 58 |
| 58 def _GenerateType(self, type_): | 59 def _GenerateType(self, type_): |
| 59 type_dict = { | 60 type_dict = { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 for property_name in properties: | 108 for property_name in properties: |
| 108 properties_list.append(self._GenerateProperty(properties[property_name])) | 109 properties_list.append(self._GenerateProperty(properties[property_name])) |
| 109 return properties_list | 110 return properties_list |
| 110 | 111 |
| 111 def _GenerateProperty(self, property_): | 112 def _GenerateProperty(self, property_): |
| 112 property_dict = { | 113 property_dict = { |
| 113 'name': property_.name, | 114 'name': property_.name, |
| 114 'type': property_.type_.name.lower(), | 115 'type': property_.type_.name.lower(), |
| 115 'optional': property_.optional, | 116 'optional': property_.optional, |
| 116 'description': property_.description, | 117 'description': property_.description, |
| 117 'properties': self._GenerateProperties(property_.properties) | 118 'properties': self._GenerateProperties(property_.properties) |
|
not at google - send to devlin
2012/07/06 02:14:30
we need to add functions here.
cduvall
2012/07/06 20:32:11
Done.
| |
| 118 } | 119 } |
|
not at google - send to devlin
2012/07/06 02:14:30
also need to specify the value at some point.
cduvall
2012/07/06 20:32:11
Done.
| |
| 119 | 120 |
| 120 if property_.type_ == model.PropertyType.CHOICES: | 121 if property_.type_ == model.PropertyType.CHOICES: |
| 121 property_dict['choices'] = [] | 122 property_dict['choices'] = [] |
| 122 for choice_name in property_.choices: | 123 for choice_name in property_.choices: |
| 123 property_dict['choices'].append(self._GenerateProperty( | 124 property_dict['choices'].append(self._GenerateProperty( |
| 124 property_.choices[choice_name])) | 125 property_.choices[choice_name])) |
| 125 # We keep track of which is last for knowing when to add "or" between | 126 # We keep track of which is last for knowing when to add "or" between |
| 126 # choices in templates. | 127 # choices in templates. |
| 127 if len(property_dict['choices']) > 0: | 128 if len(property_dict['choices']) > 0: |
| 128 property_dict['choices'][-1]['last_choice'] = True | 129 property_dict['choices'][-1]['last_choice'] = True |
| 129 elif property_.type_ == model.PropertyType.REF: | 130 elif property_.type_ == model.PropertyType.REF: |
| 130 property_dict['link'] = _GetLinkToRefType(self._namespace.name, | 131 property_dict['link'] = _GetLinkToRefType(self._namespace.name, |
| 131 property_.ref_type) | 132 property_.ref_type) |
| 132 elif property_.type_ == model.PropertyType.ARRAY: | 133 elif property_.type_ == model.PropertyType.ARRAY: |
| 133 property_dict['array'] = self._GenerateProperty(property_.item_type) | 134 property_dict['array'] = self._GenerateProperty(property_.item_type) |
| 134 else: | 135 else: |
| 135 property_dict['simple_type'] = {'type': property_dict['type']} | 136 property_dict['simple_type'] = {'type': property_dict['type']} |
| 136 return property_dict | 137 return property_dict |
| OLD | NEW |