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

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

Issue 10546078: Extension docs server: APIDataSource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes Created 8 years, 6 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
new file mode 100644
index 0000000000000000000000000000000000000000..ae55b2c57d8423df3eb76b0d025cf52bded0e19d
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import os
+
+import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
+import third_party.json_schema_compiler.model as model
+
+class APIDataSource(object):
+ """This class fetches and loads JSON APIs with the fetcher passed in with
+ |cache_builder|, so the APIs can be plugged into templates.
+ """
+ def __init__(self, cache_builder, base_paths):
+ self._cache = cache_builder.build(self._LoadAPI)
+ self._base_paths = base_paths
+
+ def _LoadAPI(self, api):
+ return json.loads(json_comment_eater.Nom(api))[0]
+
+ def __getitem__(self, key):
+ return self.get(key)
+
+ def get(self, key):
+ path, ext = os.path.splitext(key)
+ unix_name = model.UnixName(path)
+ json_path = unix_name + '.json'
+ for base_path in self._base_paths:
+ try:
+ return self._cache.get(base_path + '/' + json_path)
+ except:
+ pass
+ return None
« no previous file with comments | « chrome/common/extensions/docs/server2/PRESUBMIT.py ('k') | 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