Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/samples_data_source.py |
| diff --git a/chrome/common/extensions/docs/server2/samples_data_source.py b/chrome/common/extensions/docs/server2/samples_data_source.py |
| index 83707990f993b2986cd662d9f912abf0f672d73c..13eb42be579247bde9955ef2e77124d97b7d028f 100644 |
| --- a/chrome/common/extensions/docs/server2/samples_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/samples_data_source.py |
| @@ -14,6 +14,17 @@ import url_constants |
| DEFAULT_ICON_PATH = '/images/sample-default-icon.png' |
| +def _MakeAPILink(prefix, item, api_list): |
| + item = item.replace('chrome.', '') |
| + parts = item.split('.') |
| + api_name = [] |
| + for i in range(1, len(parts) + 1): |
| + if '.'.join(parts[:i]) in api_list: |
| + return '%s.html#%s-%s' % ('.'.join(parts[:i]), |
| + prefix, |
| + '.'.join(parts[i:])) |
| + return None |
| + |
| class SamplesDataSource(object): |
| """Constructs a list of samples and their respective files and api calls. |
| """ |
| @@ -28,6 +39,7 @@ class SamplesDataSource(object): |
| github_file_system, |
| cache_factory, |
| github_cache_factory, |
| + api_list_data_source_factory, |
| samples_path): |
| self._file_system = file_system |
| self._github_file_system = github_file_system |
| @@ -38,6 +50,7 @@ class SamplesDataSource(object): |
| self._apps_cache = github_cache_factory.Create( |
| lambda x: self._MakeSamplesList(x, is_apps=True), |
| compiled_fs.APPS) |
| + self._api_list_data_source = api_list_data_source_factory.Create() |
| self._samples_path = samples_path |
| def Create(self, request): |
| @@ -48,12 +61,16 @@ class SamplesDataSource(object): |
| self._samples_path, |
| request) |
| - def _GetApiItems(self, js_file): |
| - return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file)) |
| + def _GetAllAPINames(self): |
| + apis = [] |
| + for k1 in ['apps', 'extensions']: |
| + for k2 in ['chrome', 'experimental']: |
| + apis.extend( |
| + [api['name'] for api in self._api_list_data_source[k1][k2]]) |
| + return apis |
| - def _MakeApiLink(self, prefix, item): |
| - api, name = item.replace('chrome.', '').split('.', 1) |
| - return api + '.html#' + prefix + '-' + name |
| + def _GetAPIItems(self, js_file): |
| + return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file)) |
| def _GetDataFromManifest(self, path, file_system): |
| manifest = file_system.ReadSingle(path + '/manifest.json') |
| @@ -101,22 +118,32 @@ class SamplesDataSource(object): |
| js_contents = file_system.Read(js_files).Get() |
| api_items = set() |
| for js in js_contents.values(): |
| - api_items.update(self._GetApiItems(js)) |
| + api_items.update(self._GetAPIItems(js)) |
| api_calls = [] |
| for item in api_items: |
| if len(item.split('.')) < 3: |
| continue |
| + if item.endswith('.removeListener') or item.endswith('.hasListener'): |
| + continue |
| + api_list = self._GetAllAPINames() |
|
not at google - send to devlin
2012/09/14 00:47:20
put this right at the top of _MakeSamplesList, it
cduvall
2012/09/14 01:10:28
Done. Oops that was dumb.
|
| if item.endswith('.addListener'): |
| - item = item.replace('.addListener', '') |
| + item = item[:-len('.addListener')] |
| + link = _MakeAPILink('event', item, api_list) |
| + if link is None: |
| + continue |
| api_calls.append({ |
| 'name': item, |
| - 'link': self._MakeApiLink('event', item) |
| + 'link': link |
| }) |
| else: |
| + # TODO(cduvall): this might be a property. |
| + link = _MakeAPILink('method', item, api_list) |
| + if link is None: |
| + continue |
| api_calls.append({ |
| 'name': item, |
| - 'link': self._MakeApiLink('method', item) |
| + 'link': link |
| }) |
| manifest_data = self._GetDataFromManifest(sample_path, file_system) |
| if manifest_data is None: |