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..c53015c6ba60a3c8ff94520e06c4bd120ea74c0f 100644 | 
| --- a/chrome/common/extensions/docs/server2/samples_data_source.py | 
| +++ b/chrome/common/extensions/docs/server2/samples_data_source.py | 
| @@ -9,23 +9,13 @@ import re | 
| import compiled_file_system as compiled_fs | 
| from file_system import FileNotFoundError | 
| +from reference_resolver import ReferenceResolver | 
| import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 
| import third_party.json_schema_compiler.model as model | 
| 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 | 
| @@ -51,8 +42,12 @@ 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 | 
| + self._reference_resolver = ReferenceResolver( | 
| + api_data_source_factory.Create(None, | 
| + self.Create(None), | 
| + resolve_refs=False), | 
| + api_list_data_source_factory.Create()) | 
| 
 
not at google - send to devlin
2012/11/02 17:26:48
A good clue for when you need to introduce a Facto
 
cduvall
2012/11/03 01:30:05
Cool, thanks for the architecture tips they're sup
 
 | 
| def Create(self, request): | 
| """Returns a new SamplesDataSource bound to |request|. | 
| @@ -62,14 +57,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 +95,6 @@ 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() | 
| for filename in sorted(files): | 
| if filename.rsplit('/')[-1] != 'manifest.json': | 
| continue | 
| @@ -136,22 +122,15 @@ 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 = self._reference_resolver.GetLinkToRefType('samples', item) | 
| + 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: |