diff options
5 files changed, 110 insertions, 107 deletions
diff --git a/chrome/common/extensions/docs/server2/handlebar_dict_generator.py b/chrome/common/extensions/docs/server2/handlebar_dict_generator.py index 1e9f74f..b9a1122 100644 --- a/chrome/common/extensions/docs/server2/handlebar_dict_generator.py +++ b/chrome/common/extensions/docs/server2/handlebar_dict_generator.py @@ -82,8 +82,11 @@ class HandlebarDictGenerator(object): 'name': function.name, 'description': function.description, 'callback': self._GenerateCallback(function.callback), - 'parameters': [] + 'parameters': [], + 'returns': None } + if function.returns: + function_dict['returns'] = self._GenerateProperty(function.returns) for param in function.params: function_dict['parameters'].append(self._GenerateProperty(param)) if function_dict['callback']: @@ -157,5 +160,7 @@ class HandlebarDictGenerator(object): dst_dict['enum_values'].append({'name': enum_value}) if len(dst_dict['enum_values']) > 0: dst_dict['enum_values'][-1]['last'] = True + elif property_.instance_of: + dst_dict['simple_type'] = property_.instance_of.lower() else: - dst_dict['simple_type'] = {'simple_type': property_.type_.name.lower()} + dst_dict['simple_type'] = property_.type_.name.lower() diff --git a/chrome/common/extensions/docs/server2/static/css/api.css b/chrome/common/extensions/docs/server2/static/css/api.css index 5292571..06b2f22 100644 --- a/chrome/common/extensions/docs/server2/static/css/api.css +++ b/chrome/common/extensions/docs/server2/static/css/api.css @@ -31,7 +31,7 @@ /* This style is used because types with functions prefix the function with the * type name, using a lowercase first letter. */ -.api_reference div.summary:first-letter { +.api_reference div.lower:first-letter { text-transform: lowercase; } diff --git a/chrome/common/extensions/docs/server2/templates/private/function.html b/chrome/common/extensions/docs/server2/templates/private/function.html index 31039c1..7752e62 100644 --- a/chrome/common/extensions/docs/server2/templates/private/function.html +++ b/chrome/common/extensions/docs/server2/templates/private/function.html @@ -1,8 +1,8 @@ <div> <a name="method-{{?prefix}}{{prefix}}-{{/}}{{name}}"></a> <h4>{{name}}</h4> - <div class="summary"> - <span>{{?prefix}}{{prefix}}{{:}}chrome.{{api.name}}{{/}}.{{name}}</span>({{#parameters}}{{+partials.parameter_item}}{{^last}}, {{/}}{{/}}) + <div class="summary{{^returns}} lower{{/}}"> + <span>{{?returns}}{{+partials.variable_type}} {{/}}{{?prefix}}{{prefix}}{{:}}chrome.{{api.name}}{{/}}.{{name}}</span>({{#parameters}}{{+partials.parameter_item}}{{^last}}, {{/}}{{/}}) </div> <div class="description"> <p>{{{description}}}</p> diff --git a/chrome/common/extensions/docs/server2/test_data/test_json/expected_test_file.json b/chrome/common/extensions/docs/server2/test_data/test_json/expected_test_file.json index 1096e9c..0a25743 100644 --- a/chrome/common/extensions/docs/server2/test_data/test_json/expected_test_file.json +++ b/chrome/common/extensions/docs/server2/test_data/test_json/expected_test_file.json @@ -4,165 +4,158 @@ "callback": { "simple_type": { "simple_type": "function" - }, - "last": true, - "name": "callback", + }, + "last": true, + "name": "callback", "parameters": [ { - "functions": [], - "last": true, - "name": "results", + "functions": [], + "last": true, + "name": "results", "array": { - "functions": [], - "name": "resultsElement", + "functions": [], + "name": "resultsElement", "link": { - "text": "TypeA", + "text": "TypeA", "href": "tester.html#type-TypeA" - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null } - ], - "optional": false, + ], + "optional": false, "description": null - }, - "name": "get", + }, + "returns": null, + "name": "get", "parameters": [ { - "functions": [], - "name": "a", + "functions": [], + "name": "a", "choices": [ { - "functions": [], - "name": "a", - "simple_type": { - "simple_type": "string" - }, - "optional": true, - "properties": [], + "functions": [], + "name": "a", + "simple_type": "string", + "optional": true, + "properties": [], "description": null - }, + }, { - "functions": [], - "last": true, - "name": "a", + "functions": [], + "last": true, + "name": "a", "array": { - "functions": [], - "name": "aElement", - "simple_type": { - "simple_type": "string" - }, - "optional": false, - "properties": [], + "functions": [], + "name": "aElement", + "simple_type": "string", + "optional": false, + "properties": [], "description": null - }, - "optional": true, - "properties": [], + }, + "optional": true, + "properties": [], "description": null } - ], - "optional": false, - "properties": [], + ], + "optional": false, + "properties": [], "description": "a param" - }, + }, { "simple_type": { "simple_type": "function" - }, - "last": true, - "name": "callback", + }, + "last": true, + "name": "callback", "parameters": [ { - "functions": [], - "last": true, - "name": "results", + "functions": [], + "last": true, + "name": "results", "array": { - "functions": [], - "name": "resultsElement", + "functions": [], + "name": "resultsElement", "link": { - "text": "TypeA", + "text": "TypeA", "href": "tester.html#type-TypeA" - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null } - ], - "optional": false, + ], + "optional": false, "description": null } - ], + ], "description": "Gets stuff." } - ], - "properties": [], - "name": "tester", + ], + "properties": [], + "name": "tester", "types": [ { "properties": [ { - "functions": [], - "name": "b", + "functions": [], + "name": "b", "array": { - "functions": [], - "name": "bElement", + "functions": [], + "name": "bElement", "link": { - "text": "TypeA", + "text": "TypeA", "href": "tester.html#type-TypeA" - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null - }, - "optional": true, - "properties": [], + }, + "optional": true, + "properties": [], "description": "List of TypeA." } - ], - "functions": [], - "name": "TypeA", - "simple_type": { - "simple_type": "object" - }, + ], + "functions": [], + "name": "TypeA", + "simple_type": "object", "description": "A cool thing." } - ], + ], "events": [ { - "name": "EventA", + "name": "EventA", "parameters": [ { - "functions": [], - "name": "id", - "simple_type": { - "simple_type": "string" - }, - "optional": false, - "properties": [], + "functions": [], + "name": "id", + "simple_type": "string", + "optional": false, + "properties": [], "description": null - }, + }, { - "functions": [], - "last": true, - "name": "bookmark", + "functions": [], + "last": true, + "name": "bookmark", "link": { - "text": "TypeA", + "text": "TypeA", "href": "tester.html#type-TypeA" - }, - "optional": false, - "properties": [], + }, + "optional": false, + "properties": [], "description": null } - ], + ], "description": "A cool event." } ] diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index 33c0bc5..42d38b0 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -92,6 +92,7 @@ class Type(object): self.from_json = True self.from_client = True self.parent = parent + self.instance_of = json.get('isInstanceOf', None) _AddFunctions(self, json) _AddProperties(self, json, from_json=True, from_client=True) @@ -133,6 +134,9 @@ class Function(object): else: self.params.append(Property(self, param['name'], param, from_json=from_json, from_client=from_client)) + self.returns = None + if 'returns' in json: + self.returns = Property(self, 'return', json['returns']) class Property(object): """A property of a type OR a parameter to a function. @@ -168,6 +172,7 @@ class Property(object): self.parent = parent self.from_json = from_json self.from_client = from_client + self.instance_of = json.get('isInstanceOf', None) _AddProperties(self, json) if is_additional_properties: self.type_ = PropertyType.ADDITIONAL_PROPERTIES |