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 6d1d930fadafb980171059be3ce63903b7adb612..ed82c9c667742c173edd8f342d5113d06f05dcaf 100644 |
| --- a/chrome/common/extensions/docs/server2/samples_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/samples_data_source.py |
| @@ -8,6 +8,7 @@ import logging |
| import re |
| import compiled_file_system as compiled_fs |
| +from docs_server_utils import GetLinkToRefType |
| from file_system import FileNotFoundError |
| import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
| import third_party.json_schema_compiler.model as model |
| @@ -15,17 +16,6 @@ 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. |
| """ |
| @@ -40,6 +30,7 @@ class SamplesDataSource(object): |
| github_file_system, |
| cache_factory, |
| github_cache_factory, |
| + api_data_source_factory, |
| api_list_data_source_factory, |
| samples_path): |
| self._file_system = file_system |
| @@ -53,6 +44,9 @@ class SamplesDataSource(object): |
| compiled_fs.APPS) |
| self._api_list_data_source = api_list_data_source_factory.Create() |
| self._samples_path = samples_path |
| + self._api_data_source = api_data_source_factory.Create(None, |
|
not at google - send to devlin
2012/11/01 22:00:49
Could you pass in a fake request rather than None?
cduvall
2012/11/02 01:53:53
Done.
|
| + self.Create(None), |
| + resolve_refs=False) |
| def Create(self, request): |
| """Returns a new SamplesDataSource bound to |request|. |
| @@ -62,14 +56,6 @@ class SamplesDataSource(object): |
| self._samples_path, |
| request) |
| - 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 _GetAPIItems(self, js_file): |
| return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file)) |
| @@ -108,7 +94,7 @@ class SamplesDataSource(object): |
| def _MakeSamplesList(self, files, is_apps=False): |
| file_system = self._github_file_system if is_apps else self._file_system |
| samples_list = [] |
| - api_list = self._GetAllAPINames() |
| + api_list = self._api_list_data_source.GetAllNames() |
| for filename in sorted(files): |
| if filename.rsplit('/')[-1] != 'manifest.json': |
| continue |
| @@ -136,22 +122,18 @@ class SamplesDataSource(object): |
| continue |
| if item.endswith('.addListener'): |
| item = item[:-len('.addListener')] |
| - link = _MakeAPILink('event', item, api_list) |
| - if link is None: |
| - continue |
| - api_calls.append({ |
| - 'name': item, |
| - 'link': link |
| - }) |
| - else: |
| - # TODO(cduvall): this might be a property or a type. |
| - link = _MakeAPILink('method', item, api_list) |
| - if link is None: |
| - continue |
| - api_calls.append({ |
| - 'name': item, |
| - 'link': link |
| - }) |
| + if item.startswith('chrome.'): |
| + item = item[len('chrome.'):] |
| + ref_data = GetLinkToRefType('samples', |
| + item, |
| + self._api_data_source, |
| + api_list) |
| + if ref_data is None: |
| + continue |
| + api_calls.append({ |
| + 'name': ref_data['text'], |
| + 'link': ref_data['href'] |
| + }) |
| try: |
| manifest_data = self._GetDataFromManifest(sample_path, file_system) |
| except FileNotFoundError as e: |