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 fe5a1c2106464e2f1cf287f24bbbd480fb644b81..708f4d3475f17f07501be940d54bee7da8211a56 100644 |
| --- a/chrome/common/extensions/docs/server2/api_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_data_source.py |
| @@ -13,6 +13,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. |
| + """ |
| + def __init__(self, api_name, samples): |
| + self._api_name = api_name |
| + self._samples = samples |
| + |
| + def get(self, key): |
| + return 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. |
| @@ -63,6 +74,7 @@ class APIDataSource(object): |
| self._base_path + '/_permission_features.json') |
| except FileNotFoundError: |
| return None |
| + perms = dict([(model.UnixName(k), v) for k, v in perms.iteritems()]) |
|
not at google - send to devlin
2012/08/13 01:51:11
i think that just dict(...) will work, don't need
cduvall
2012/08/13 17:47:06
Done.
|
| api_perms = perms.get(path, None) |
| if api_perms is None: |
| return None |
| @@ -70,17 +82,14 @@ class APIDataSource(object): |
| api_perms['dev'] = True |
| return api_perms |
| - 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) |
| @@ -90,12 +99,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 FileNotFoundError: |
| try: |
| - return self._GenerateHandlebarContext(key, |
| + return self._GenerateHandlebarContext( |
| self._idl_cache.GetFromFile(self._base_path + '/' + idl_path), |
| path) |
| except FileNotFoundError as e: |