Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/api_data_source.py |
| diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py |
| index 5e07ea25b0e763abe88890d40f2cd9db9bda4b96..f3f5d0810fa68a5403810f87981d2e43b58ef34b 100644 |
| --- a/chrome/common/extensions/docs/server2/api_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_data_source.py |
| @@ -12,6 +12,17 @@ import third_party.json_schema_compiler.model as model |
| import third_party.json_schema_compiler.idl_schema as idl_schema |
| import third_party.json_schema_compiler.idl_parser as idl_parser |
| +class _LazySamplesGetter(object): |
| + """This class is needed so that an extensions API page does not have to fetch |
| + the apps samples page and vice versa. |
|
not at google - send to devlin
2012/08/10 06:02:18
nice
|
| + """ |
| + def __init__(self, api_name, samples): |
| + self._api_name = api_name |
| + self._samples = samples |
| + |
| + def get(self, key): |
| + self._samples.FilterSamples(key, self._api_name) |
| + |
| class APIDataSource(object): |
| """This class fetches and loads JSON APIs from the FileSystem passed in with |
| |cache_builder|, so the APIs can be plugged into templates. |
| @@ -67,17 +78,14 @@ class APIDataSource(object): |
| except Exception: |
| return None |
| - def _GenerateHandlebarContext(self, api_name, handlebar, path): |
| - return_dict = { 'permissions': self._GetFeature(path) } |
| - return_dict.update(handlebar.Generate( |
| - self._FilterSamples(api_name, self._samples.values()))) |
| + def _GenerateHandlebarContext(self, handlebar, path): |
| + return_dict = { |
| + 'permissions': self._GetFeature(path), |
| + 'samples': _LazySamplesGetter(path, self._samples) |
| + } |
| + return_dict.update(handlebar.Generate()) |
| return return_dict |
| - def _FilterSamples(self, api_name, samples): |
| - api_search = '.' + api_name + '.' |
| - return [sample for sample in samples |
| - if any(api_search in api['name'] for api in sample['api_calls'])] |
| - |
| def __getitem__(self, key): |
| return self.get(key) |
| @@ -87,12 +95,12 @@ class APIDataSource(object): |
| json_path = unix_name + '.json' |
| idl_path = unix_name + '.idl' |
| try: |
| - return self._GenerateHandlebarContext(key, |
| + return self._GenerateHandlebarContext( |
| self._json_cache.GetFromFile(self._base_path + '/' + json_path), |
| path) |
| except OSError: |
| try: |
| - return self._GenerateHandlebarContext(key, |
| + return self._GenerateHandlebarContext( |
| self._idl_cache.GetFromFile(self._base_path + '/' + idl_path), |
| path) |
| except OSError as e: |