Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/common/extensions/docs/server2/handlebar_dict_generator.py

Issue 10800047: Extension Docs Server Version 2: Various fixes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ok now it should work Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import third_party.json_schema_compiler.model as model 9 import third_party.json_schema_compiler.model as model
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 'properties': self._GenerateProperties(self._namespace.properties) 62 'properties': self._GenerateProperties(self._namespace.properties)
63 } 63 }
64 except Exception as e: 64 except Exception as e:
65 logging.info(e) 65 logging.info(e)
66 66
67 def _GenerateType(self, type_): 67 def _GenerateType(self, type_):
68 type_dict = { 68 type_dict = {
69 'name': type_.name, 69 'name': type_.name,
70 'description': type_.description, 70 'description': type_.description,
71 'properties': self._GenerateProperties(type_.properties), 71 'properties': self._GenerateProperties(type_.properties),
72 'functions': self._GenerateFunctions(type_.functions) 72 'functions': self._GenerateFunctions(type_.functions),
73 'events': map(self._GenerateEvent, type_.events.values())
73 } 74 }
74 self._RenderTypeInformation(type_, type_dict) 75 self._RenderTypeInformation(type_, type_dict)
75 return type_dict 76 return type_dict
76 77
77 def _GenerateFunctions(self, functions): 78 def _GenerateFunctions(self, functions):
78 return map(self._GenerateFunction, functions.values()) 79 return map(self._GenerateFunction, functions.values())
79 80
80 def _GenerateFunction(self, function): 81 def _GenerateFunction(self, function):
81 function_dict = { 82 function_dict = {
82 'name': function.name, 83 'name': function.name,
(...skipping 17 matching lines...) Expand all
100 'name': event.name, 101 'name': event.name,
101 'description': event.description, 102 'description': event.description,
102 'parameters': map(self._GenerateProperty, event.params) 103 'parameters': map(self._GenerateProperty, event.params)
103 } 104 }
104 if len(event_dict['parameters']) > 0: 105 if len(event_dict['parameters']) > 0:
105 event_dict['parameters'][-1]['last'] = True 106 event_dict['parameters'][-1]['last'] = True
106 return event_dict 107 return event_dict
107 108
108 def _GenerateCallback(self, callback): 109 def _GenerateCallback(self, callback):
109 if not callback: 110 if not callback:
110 return {} 111 return None
111 callback_dict = { 112 callback_dict = {
112 'name': 'callback', 113 'name': 'callback',
113 'description': callback.description, 114 'description': callback.description,
114 'simple_type': {'simple_type': 'function'}, 115 'simple_type': {'simple_type': 'function'},
115 'optional': callback.optional, 116 'optional': callback.optional,
116 'parameters': [] 117 'parameters': []
117 } 118 }
118 for param in callback.params: 119 for param in callback.params:
119 callback_dict['parameters'].append(self._GenerateProperty(param)) 120 callback_dict['parameters'].append(self._GenerateProperty(param))
120 if (len(callback_dict['parameters']) > 0): 121 if (len(callback_dict['parameters']) > 0):
(...skipping 21 matching lines...) Expand all
142 return property_dict 143 return property_dict
143 144
144 def _RenderTypeInformation(self, property_, dst_dict): 145 def _RenderTypeInformation(self, property_, dst_dict):
145 if property_.type_ == model.PropertyType.CHOICES: 146 if property_.type_ == model.PropertyType.CHOICES:
146 dst_dict['choices'] = map(self._GenerateProperty, 147 dst_dict['choices'] = map(self._GenerateProperty,
147 property_.choices.values()) 148 property_.choices.values())
148 # We keep track of which is last for knowing when to add "or" between 149 # We keep track of which is last for knowing when to add "or" between
149 # choices in templates. 150 # choices in templates.
150 if len(dst_dict['choices']) > 0: 151 if len(dst_dict['choices']) > 0:
151 dst_dict['choices'][-1]['last'] = True 152 dst_dict['choices'][-1]['last'] = True
153 elif property_.type_ == model.PropertyType.ADDITIONAL_PROPERTIES:
154 dst_dict['additional_properties'] = True
152 elif property_.type_ == model.PropertyType.REF: 155 elif property_.type_ == model.PropertyType.REF:
153 dst_dict['link'] = _GetLinkToRefType(self._namespace.name, 156 dst_dict['link'] = _GetLinkToRefType(self._namespace.name,
154 property_.ref_type) 157 property_.ref_type)
155 elif property_.type_ == model.PropertyType.ARRAY: 158 elif property_.type_ == model.PropertyType.ARRAY:
156 dst_dict['array'] = self._GenerateProperty(property_.item_type) 159 dst_dict['array'] = self._GenerateProperty(property_.item_type)
157 elif property_.type_ == model.PropertyType.ENUM: 160 elif property_.type_ == model.PropertyType.ENUM:
158 dst_dict['enum_values'] = [] 161 dst_dict['enum_values'] = []
159 for enum_value in property_.enum_values: 162 for enum_value in property_.enum_values:
160 dst_dict['enum_values'].append({'name': enum_value}) 163 dst_dict['enum_values'].append({'name': enum_value})
161 if len(dst_dict['enum_values']) > 0: 164 if len(dst_dict['enum_values']) > 0:
162 dst_dict['enum_values'][-1]['last'] = True 165 dst_dict['enum_values'][-1]['last'] = True
163 elif property_.instance_of: 166 elif property_.instance_of:
164 dst_dict['simple_type'] = property_.instance_of.lower() 167 dst_dict['simple_type'] = property_.instance_of.lower()
165 else: 168 else:
166 dst_dict['simple_type'] = property_.type_.name.lower() 169 dst_dict['simple_type'] = property_.type_.name.lower()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/fake_url_fetcher.py ('k') | chrome/common/extensions/docs/server2/local_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698