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

Side by Side Diff: chrome/common/extensions/docs/server2/api_list_data_source.py

Issue 68873003: Docserver: Serve docs out of src/ not src/chrome/common/extensions. This allows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix samples Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from operator import itemgetter 5 from operator import itemgetter
6 import os 6 import os
7 import posixpath 7 import posixpath
8 8
9 from svn_constants import PUBLIC_TEMPLATE_PATH
10 import docs_server_utils as utils 9 import docs_server_utils as utils
10 from extensions_paths import PUBLIC_TEMPLATES
11 11
12 def _GetAPICategory(api, documented_apis): 12 def _GetAPICategory(api, documented_apis):
13 name = api['name'] 13 name = api['name']
14 if (name.endswith('Private') or 14 if (name.endswith('Private') or
15 name not in documented_apis): 15 name not in documented_apis):
16 return 'private' 16 return 'private'
17 if name.startswith('experimental.'): 17 if name.startswith('experimental.'):
18 return 'experimental' 18 return 'experimental'
19 return 'chrome' 19 return 'chrome'
20 20
(...skipping 23 matching lines...) Expand all
44 self._cache = compiled_fs_factory.Create(file_system, 44 self._cache = compiled_fs_factory.Create(file_system,
45 self._CollectDocumentedAPIs, 45 self._CollectDocumentedAPIs,
46 APIListDataSource) 46 APIListDataSource)
47 self._features_bundle = features_bundle 47 self._features_bundle = features_bundle
48 self._object_store_creator = object_store_creator 48 self._object_store_creator = object_store_creator
49 49
50 def _CollectDocumentedAPIs(self, base_dir, files): 50 def _CollectDocumentedAPIs(self, base_dir, files):
51 def GetDocumentedAPIsForPlatform(names, platform): 51 def GetDocumentedAPIsForPlatform(names, platform):
52 public_templates = [] 52 public_templates = []
53 for root, _, files in self._file_system.Walk(posixpath.join( 53 for root, _, files in self._file_system.Walk(posixpath.join(
54 PUBLIC_TEMPLATE_PATH, platform)): 54 PUBLIC_TEMPLATES, platform)):
55 public_templates.extend( 55 public_templates.extend(
56 ('%s/%s' % (root, name)).lstrip('/') for name in files) 56 ('%s/%s' % (root, name)).lstrip('/') for name in files)
57 template_names = set(os.path.splitext(name)[0] 57 template_names = set(os.path.splitext(name)[0]
58 for name in public_templates) 58 for name in public_templates)
59 return [name.replace('_', '.') for name in template_names] 59 return [name.replace('_', '.') for name in template_names]
60 api_names = set(utils.SanitizeAPIName(name) for name in files) 60 api_names = set(utils.SanitizeAPIName(name) for name in files)
61 return { 61 return {
62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), 62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'),
63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') 63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions')
64 } 64 }
65 65
66 def _GenerateAPIDict(self): 66 def _GenerateAPIDict(self):
67 documented_apis = self._cache.GetFromFileListing( 67 documented_apis = self._cache.GetFromFileListing(PUBLIC_TEMPLATES).Get()
68 PUBLIC_TEMPLATE_PATH).Get()
69 api_features = self._features_bundle.GetAPIFeatures().Get() 68 api_features = self._features_bundle.GetAPIFeatures().Get()
70 69
71 def FilterAPIs(platform): 70 def FilterAPIs(platform):
72 return (api for api in api_features.itervalues() 71 return (api for api in api_features.itervalues()
73 if platform in api['platforms']) 72 if platform in api['platforms'])
74 73
75 def MakeDictForPlatform(platform): 74 def MakeDictForPlatform(platform):
76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } 75 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] }
77 for api in FilterAPIs(platform): 76 for api in FilterAPIs(platform):
78 if api['name'] in documented_apis[platform]: 77 if api['name'] in documented_apis[platform]:
(...skipping 18 matching lines...) Expand all
97 96
98 def _GetCachedAPIData(self): 97 def _GetCachedAPIData(self):
99 data = self._object_store.Get('api_data').Get() 98 data = self._object_store.Get('api_data').Get()
100 if data is None: 99 if data is None:
101 data = self._factory._GenerateAPIDict() 100 data = self._factory._GenerateAPIDict()
102 self._object_store.Set('api_data', data) 101 self._object_store.Set('api_data', data)
103 return data 102 return data
104 103
105 def get(self, key): 104 def get(self, key):
106 return self._GetCachedAPIData().get(key) 105 return self._GetCachedAPIData().get(key)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698