OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 from code import Code | 5 from code import Code |
6 from model import PropertyType | 6 from model import PropertyType |
7 | 7 |
8 from datetime import datetime | 8 from datetime import datetime |
9 | 9 |
10 LICENSE = """// Copyright %s The Chromium Authors. All rights reserved. | 10 LICENSE = """// Copyright %s The Chromium Authors. All rights reserved. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 self._TypeToJsType(namespace_name, function.returns), | 94 self._TypeToJsType(namespace_name, function.returns), |
95 '', False, function.returns.description) | 95 '', False, function.returns.description) |
96 | 96 |
97 if function.deprecated: | 97 if function.deprecated: |
98 c.Append('@deprecated %s' % function.deprecated) | 98 c.Append('@deprecated %s' % function.deprecated) |
99 | 99 |
100 c.Append(self.GetSeeLink(namespace_name, 'method', function.name)) | 100 c.Append(self.GetSeeLink(namespace_name, 'method', function.name)) |
101 | 101 |
102 c.Eblock(' */') | 102 c.Eblock(' */') |
103 | 103 |
104 def AppendTypeJsDoc(self, c, namespace_name, js_type, optional): | |
Dan Beam
2017/01/11 23:04:26
s/optional/nullable/
optional means {type=} in JS
dmazzoni
2017/01/11 23:23:57
Done.
| |
105 """Appends the documentation for a type as a Code. | |
106 """ | |
107 c.Append('@type {') | |
108 js_type_str = self._TypeToJsType(namespace_name, js_type).Render() | |
109 if optional: | |
110 if js_type_str[0] == '!': | |
Dan Beam
2017/01/11 23:04:26
when does a nullable param have a !Type? these ar
dmazzoni
2017/01/11 23:23:57
Exactly, but _TypeToJsType, below, always adds '!'
| |
111 js_type_str = js_type_str[1:] | |
112 js_type_str = '?' + js_type_str | |
113 c.Append(js_type_str, new_line=False) | |
114 c.Append('}', new_line=False) | |
115 | |
104 def _FunctionToJsFunction(self, namespace_name, function): | 116 def _FunctionToJsFunction(self, namespace_name, function): |
105 """Converts a model.Function to a JS type (i.e., function([params])...)""" | 117 """Converts a model.Function to a JS type (i.e., function([params])...)""" |
106 c = Code() | 118 c = Code() |
107 c.Append('function(') | 119 c.Append('function(') |
108 for i, param in enumerate(function.params): | 120 for i, param in enumerate(function.params): |
109 c.Concat(self._TypeToJsType(namespace_name, param.type_), new_line=False) | 121 c.Concat(self._TypeToJsType(namespace_name, param.type_), new_line=False) |
110 if i is not len(function.params) - 1: | 122 if i is not len(function.params) - 1: |
111 c.Append(', ', new_line=False, strip_right=False) | 123 c.Append(', ', new_line=False, strip_right=False) |
112 c.Append('):', new_line=False) | 124 c.Append('):', new_line=False) |
113 | 125 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 """Returns a @see link for a given API 'object' (type, method, or event). | 172 """Returns a @see link for a given API 'object' (type, method, or event). |
161 """ | 173 """ |
162 | 174 |
163 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on | 175 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on |
164 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have | 176 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have |
165 # '.'s in them (like app.window), which should resolve to 'app_window'. | 177 # '.'s in them (like app.window), which should resolve to 'app_window'. |
166 # Luckily, the doc server has excellent url resolution, and knows exactly | 178 # Luckily, the doc server has excellent url resolution, and knows exactly |
167 # what we mean. This saves us from needing any complicated logic here. | 179 # what we mean. This saves us from needing any complicated logic here. |
168 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' % | 180 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' % |
169 (namespace_name, object_type, object_name)) | 181 (namespace_name, object_type, object_name)) |
OLD | NEW |