Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4693)

Unified Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 10825067: Extensions Docs Server: Apps samples page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Samples on API pages Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fb1cbf2a9b774b85a8741e2ef6a71c48c8d46835 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -12,6 +12,31 @@ 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):
+ def __init__(self, api_name, samples):
+ self._api_search = '_' + api_name + '_'
+ self._samples = samples
+
+ def _FilterSamples(self, key, samples):
+ logging.info(self._api_search)
not at google - send to devlin 2012/08/09 07:52:36 remove logging?
cduvall 2012/08/09 19:20:08 Done.
+ samples_list = []
+ for sample in samples.get(key):
+ api_calls_unix = [model.UnixName(call['name'])
+ for call in sample['api_calls']]
+ for call in api_calls_unix:
+ if self._api_search in call:
+ samples_list.append(sample)
not at google - send to devlin 2012/08/09 07:52:36 All this seems like it could be a method on Sample
cduvall 2012/08/09 19:20:08 Done.
+ break
+ return samples_list
+
+ def get(self, key):
+ # Try to get the samples, but it's not a big deal if we can't. It's more
+ # important to render the API page.
not at google - send to devlin 2012/08/09 07:52:36 I don't follow this comment nor why you need to ca
cduvall 2012/08/09 19:20:08 Done.
+ try:
+ return self._FilterSamples(key, self._samples)
+ except Exception as e:
+ logging.warn(e)
+
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 +92,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 +109,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:

Powered by Google App Engine
This is Rietveld 408576698