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

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

Issue 10835012: Extension Docs Server: Include a list of samples used in the api reference page. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 5 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 d4ea2a2cea1b3930a8a76d06d89e94c51b1a0d16..ef9f3d5ab00d4ffb335b968362facb027f32f6af 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -16,24 +16,42 @@ 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.
"""
- def __init__(self, cache_builder, base_path):
- self._json_cache = cache_builder.build(self._LoadJsonAPI)
- self._idl_cache = cache_builder.build(self._LoadIdlAPI)
- self._permissions_cache = cache_builder.build(self._LoadPermissions)
- self._base_path = base_path
+ class Factory(object):
+ def __init__(self, cache_builder, base_path, samples_factory):
+ self._permissions_cache = cache_builder.build(self._LoadPermissions)
+ self._json_cache = cache_builder.build(self._LoadJsonAPI)
+ self._idl_cache = cache_builder.build(self._LoadIdlAPI)
+ self._samples_factory = samples_factory
+ self._base_path = base_path
+
+ def Create(self, request):
+ return APIDataSource(self._permissions_cache,
+ self._json_cache,
+ self._idl_cache,
+ self._base_path,
+ self._samples_factory.Create(request))
- def _LoadJsonAPI(self, api):
- generator = HandlebarDictGenerator(
- json.loads(json_comment_eater.Nom(api))[0])
- return generator.Generate()
+ def _LoadPermissions(self, json_str):
+ return json.loads(json_comment_eater.Nom(json_str))
- def _LoadIdlAPI(self, api):
- idl = idl_parser.IDLParser().ParseData(api)
- generator = HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0])
- return generator.Generate()
+ def _LoadJsonAPI(self, api):
+ return HandlebarDictGenerator(json.loads(json_comment_eater.Nom(api))[0])
- def _LoadPermissions(self, perms_json):
- return json.loads(json_comment_eater.Nom(perms_json))
+ def _LoadIdlAPI(self, api):
+ idl = idl_parser.IDLParser().ParseData(api)
+ return HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0])
+
+ def __init__(self,
+ permissions_cache,
+ json_cache,
+ idl_cache,
+ base_path,
+ samples):
+ self._base_path = base_path
+ self._permissions_cache = permissions_cache
+ self._json_cache = json_cache
+ self._idl_cache = idl_cache
+ self._samples = samples
def _GetFeature(self, path):
# Remove 'experimental_' from path name to match the keys in
@@ -49,9 +67,9 @@ class APIDataSource(object):
except Exception:
return None
- def _AddPermissionsDict(self, api_dict, path):
+ def _GenerateHandlebarContext(self, handlebar, path):
return_dict = { 'permissions': self._GetFeature(path) }
- return_dict.update(api_dict)
+ return_dict.update(handlebar.Generate(self._samples.values()))
return return_dict
def __getitem__(self, key):
@@ -63,12 +81,11 @@ class APIDataSource(object):
json_path = unix_name + '.json'
idl_path = unix_name + '.idl'
try:
- return self._AddPermissionsDict(self._json_cache.GetFromFile(
+ return self._GenerateHandlebarContext(self._json_cache.GetFromFile(
self._base_path + '/' + json_path), path)
except Exception:
try:
- return self._AddPermissionsDict(self._idl_cache.GetFromFile(
+ return self._GenerateHandlebarContext(self._idl_cache.GetFromFile(
self._base_path + '/' + idl_path), path)
except Exception as e:
not at google - send to devlin 2012/08/01 20:56:32 Like I did in that other patch, could you change t
chebert 2012/08/02 18:40:23 Done.
- logging.warn(e)
raise

Powered by Google App Engine
This is Rietveld 408576698