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

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: more changes 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
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..0f887b2375ecee1738aa0b7131ee5780d156c085 100644
--- a/chrome/common/extensions/docs/server2/samples_data_source.py
+++ b/chrome/common/extensions/docs/server2/samples_data_source.py
@@ -14,6 +14,17 @@ import url_constants
DEFAULT_ICON_PATH = '/images/sample-default-icon.png'
+def _MakeAPILink(prefix, item, api_list):
+ item = item.replace('chrome.', '')
+ parts = item.split('.')
+ api_name = []
+ 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
+
class SamplesDataSource(object):
"""Constructs a list of samples and their respective files and api calls.
"""
@@ -28,6 +39,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 +50,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 +61,16 @@ class SamplesDataSource(object):
self._samples_path,
request)
- def _GetApiItems(self, js_file):
- return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file))
+ def _GetAllAPINames(self):
+ 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 _MakeApiLink(self, prefix, item):
- api, name = item.replace('chrome.', '').split('.', 1)
- return api + '.html#' + prefix + '-' + name
+ def _GetAPIItems(self, js_file):
+ return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file))
def _GetDataFromManifest(self, path, file_system):
manifest = file_system.ReadSingle(path + '/manifest.json')
@@ -90,6 +107,7 @@ class SamplesDataSource(object):
def _MakeSamplesList(self, files, is_apps=False):
file_system = self._github_file_system if is_apps else self._file_system
samples_list = []
+ api_list = self._GetAllAPINames()
for filename in sorted(files):
if filename.rsplit('/')[-1] != 'manifest.json':
continue
@@ -101,22 +119,31 @@ 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') or item.endswith('.hasListener'):
+ continue
if item.endswith('.addListener'):
- item = item.replace('.addListener', '')
+ item = item[:-len('.addListener')]
+ link = _MakeAPILink('event', item, api_list)
+ if link is None:
+ continue
api_calls.append({
'name': item,
- 'link': self._MakeApiLink('event', item)
+ 'link': link
})
else:
+ # TODO(cduvall): this might be a property or a type.
+ link = _MakeAPILink('method', item, api_list)
+ 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') | chrome/common/extensions/docs/server2/samples_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698