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

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: fixed templates 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..412680ee4f227210bd30b6a88c0d6a39bb56a577 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())
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:
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698