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

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

Issue 10830115: Injection stuff. (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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/handlebar_dict_generator.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 60d7f0800c4f2326d9f51f9e6fe94c8a3c9efe07..d9288cdd6967603502f175c411ba90225438f7ca 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -17,19 +17,41 @@ class APIDataSource(object):
|cache_builder|, so the APIs can be plugged into templates.
"""
class Factory(object):
- def __init__(self, cache_builder, base_path):
- self._cache_builder = cache_builder
+ def __init__(self, cache_builder, base_path, samples_factory):
+ 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
+ self._samples_factory = samples_factory
- def Create(self, samples):
- return APIDataSource(self._cache_builder, self._base_path, samples)
+ def Create(self, request):
+ return APIDataSource(self._json_cache,
+ self._idl_cache,
+ self._permissions_cache,
+ self._samples_factory.Create(request),
+ self._base_path)
- def __init__(self, cache_builder, base_path, samples):
- 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._base_path = base_path
+ def _LoadJsonAPI(self, api):
+ return HandlebarDictGenerator(json.loads(json_comment_eater.Nom(api))[0])
+
+ def _LoadIdlAPI(self, api):
+ idl = idl_parser.IDLParser().ParseData(api)
+ return HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0])
+
+ def _LoadPermissions(self, json_str):
+ return json.loads(json_comment_eater.Nom(json_str))
+
+ def __init__(self,
+ json_cache,
+ idl_cache,
+ permissions_cache,
+ samples,
+ base_path):
+ self._json_cache = json_cache
+ self._idl_cache = idl_cache
+ self._permissions_cache = permissions_cache
self._samples = samples
+ self._base_path = base_path
def _GetFeature(self, path):
# Remove 'experimental_' from path name to match the keys in
@@ -45,23 +67,9 @@ class APIDataSource(object):
except Exception:
return None
- def _LoadPermissions(self, perms_json):
- return json.loads(json_comment_eater.Nom(perms_json))
-
- def _LoadJsonAPI(self, api):
- generator = HandlebarDictGenerator(
- json.loads(json_comment_eater.Nom(api))[0], self._samples)
- return generator.Generate()
-
- def _LoadIdlAPI(self, api):
- idl = idl_parser.IDLParser().ParseData(api)
- generator = HandlebarDictGenerator(
- idl_schema.IDLSchema(idl).process()[0], self._samples)
- return generator.Generate()
-
- 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.GetAll()))
return return_dict
def __getitem__(self, key):
@@ -73,12 +81,11 @@ class APIDataSource(object):
json_path = unix_name + '.json'
idl_path = unix_name + '.idl'
try:
- return self._AddPermissionsDict(self._json_cache.GetFromFile(
- self._base_path + '/' + json_path), path)
- except Exception:
+ return self._GenerateHandlebarContext(
+ self._json_cache.GetFromFile(self._base_path + '/' + json_path), path)
+ except OSError:
try:
- return self._AddPermissionsDict(self._idl_cache.GetFromFile(
- self._base_path + '/' + idl_path), path)
- except Exception as e:
- logging.warn(e)
- raise
+ return self._GenerateHandlebarContext(
+ self._idl_cache.GetFromFile(self._base_path + '/' + idl_path), path)
+ except OSError:
+ return None
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/handlebar_dict_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698