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

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

Issue 10910208: Extensions Docs Server: Fix 404s from API links on the samples page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | « chrome/common/extensions/docs/server2/handler.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/server2/samples_data_source.py
diff --git a/chrome/common/extensions/docs/server2/samples_data_source.py b/chrome/common/extensions/docs/server2/samples_data_source.py
index 83707990f993b2986cd662d9f912abf0f672d73c..b445481b95141f2982d8dbd950690b640a52ccda 100644
--- a/chrome/common/extensions/docs/server2/samples_data_source.py
+++ b/chrome/common/extensions/docs/server2/samples_data_source.py
@@ -28,6 +28,7 @@ class SamplesDataSource(object):
github_file_system,
cache_factory,
github_cache_factory,
+ api_list_data_source_factory,
samples_path):
self._file_system = file_system
self._github_file_system = github_file_system
@@ -38,6 +39,7 @@ class SamplesDataSource(object):
self._apps_cache = github_cache_factory.Create(
lambda x: self._MakeSamplesList(x, is_apps=True),
compiled_fs.APPS)
+ self._api_list_data_source = api_list_data_source_factory.Create()
self._samples_path = samples_path
def Create(self, request):
@@ -48,12 +50,28 @@ class SamplesDataSource(object):
self._samples_path,
request)
- def _GetApiItems(self, js_file):
+ def _MakeAPIList(self):
not at google - send to devlin 2012/09/11 23:40:00 _GetAllAPINames? we're going to be calculating it
cduvall 2012/09/12 21:59:05 Done.
+ apis = []
+ for k1 in ['apps', 'extensions']:
+ for k2 in ['chrome', 'experimental']:
+ apis.extend(
+ [api['name'] for api in self._api_list_data_source[k1][k2]])
+ return apis
+
+ def _GetAPIItems(self, js_file):
return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file))
- def _MakeApiLink(self, prefix, item):
- api, name = item.replace('chrome.', '').split('.', 1)
- return api + '.html#' + prefix + '-' + name
+ def _MakeAPILink(self, prefix, item):
+ item = item.replace('chrome.', '')
+ parts = item.split('.')
+ api_name = []
+ api_list = self._MakeAPIList()
+ for i in range(1, len(parts) + 1):
+ if '.'.join(parts[:i]) in api_list:
+ return '%s.html#%s-%s' % ('.'.join(parts[:i]),
+ prefix,
+ '.'.join(parts[i:]))
+ return None
def _GetDataFromManifest(self, path, file_system):
manifest = file_system.ReadSingle(path + '/manifest.json')
@@ -101,22 +119,30 @@ class SamplesDataSource(object):
js_contents = file_system.Read(js_files).Get()
api_items = set()
for js in js_contents.values():
- api_items.update(self._GetApiItems(js))
+ api_items.update(self._GetAPIItems(js))
api_calls = []
for item in api_items:
if len(item.split('.')) < 3:
continue
+ if item.endswith('.removeListener'):
+ continue
not at google - send to devlin 2012/09/11 23:40:00 You might also want to add hasListener for complet
cduvall 2012/09/12 21:59:05 Done.
if item.endswith('.addListener'):
- item = item.replace('.addListener', '')
+ item = item[:-len('.addListener')]
+ link = self._MakeAPILink('event', item)
+ if link is None:
+ continue
api_calls.append({
'name': item,
- 'link': self._MakeApiLink('event', item)
+ 'link': link
})
else:
+ link = self._MakeAPILink('method', item)
not at google - send to devlin 2012/09/11 23:40:00 TODO(cduvall): this might be a property.
cduvall 2012/09/12 21:59:05 Done.
not at google - send to devlin 2012/09/14 00:47:19 or a type (sorry)
cduvall 2012/09/14 01:10:28 Done.
+ if link is None:
+ continue
api_calls.append({
'name': item,
- 'link': self._MakeApiLink('method', item)
+ 'link': link
})
manifest_data = self._GetDataFromManifest(sample_path, file_system)
if manifest_data is None:
« no previous file with comments | « chrome/common/extensions/docs/server2/handler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698