OLD | NEW |
---|---|
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 | 9 from svn_constants import PUBLIC_TEMPLATE_PATH |
10 import docs_server_utils as utils | 10 import docs_server_utils as utils |
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 |
21 | 21 |
22 class APIListDataSource(object): | 22 class APIListDataSource(object): |
23 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs | 23 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs |
24 for extensions and apps that are used in the api_index.html and | 24 for extensions and apps that are used in the api_index.html, |
25 experimental.html pages. | 25 experimental.html, and private_apis.html pages. |
26 | 26 |
27 An API is considered listable if it is listed in _api_features.json, | 27 An API is considered listable if it is listed in _api_features.json, |
28 it has a corresponding HTML file in the public template path, and one of | 28 it has a corresponding HTML file in the public template path, and one of |
29 the following conditions is met: | 29 the following conditions is met: |
30 - It has no "dependencies" or "extension_types" properties in _api_features | 30 - It has no "dependencies" or "extension_types" properties in _api_features |
31 - It has an "extension_types" property in _api_features with either/both | 31 - It has an "extension_types" property in _api_features with either/both |
32 "extension"/"platform_app" values present. | 32 "extension"/"platform_app" values present. |
33 - It has a dependency in _{api,manifest,permission}_features with an | 33 - It has a dependency in _{api,manifest,permission}_features with an |
34 "extension_types" property where either/both "extension"/"platform_app" | 34 "extension_types" property where either/both "extension"/"platform_app" |
35 values are present. | 35 values are present. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 api_features = self._features_bundle.GetAPIFeatures() | 69 api_features = self._features_bundle.GetAPIFeatures() |
70 | 70 |
71 def FilterAPIs(platform): | 71 def FilterAPIs(platform): |
72 return (api for api in api_features.itervalues() | 72 return (api for api in api_features.itervalues() |
73 if platform in api['platforms']) | 73 if platform in api['platforms']) |
74 | 74 |
75 def MakeDictForPlatform(platform): | 75 def MakeDictForPlatform(platform): |
76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
77 for api in FilterAPIs(platform): | 77 for api in FilterAPIs(platform): |
78 category = _GetAPICategory(api, documented_apis[platform]) | 78 category = _GetAPICategory(api, documented_apis[platform]) |
79 platform_dict[category].append(api) | 79 if api['name'] in documented_apis[platform]: |
not at google - send to devlin
2013/11/05 21:23:12
move this up a line so that it includes the "categ
dhnishi (use Chromium)
2013/11/05 21:28:45
Done.
| |
80 platform_dict[category].append(api) | |
80 for category, apis in platform_dict.iteritems(): | 81 for category, apis in platform_dict.iteritems(): |
81 platform_dict[category] = sorted(apis, key=itemgetter('name')) | 82 platform_dict[category] = sorted(apis, key=itemgetter('name')) |
82 utils.MarkLast(platform_dict[category]) | 83 utils.MarkLast(platform_dict[category]) |
83 return platform_dict | 84 return platform_dict |
84 | 85 |
85 return { | 86 return { |
86 'apps': MakeDictForPlatform('apps'), | 87 'apps': MakeDictForPlatform('apps'), |
87 'extensions': MakeDictForPlatform('extensions') | 88 'extensions': MakeDictForPlatform('extensions') |
88 } | 89 } |
89 | 90 |
90 def Create(self): | 91 def Create(self): |
91 return APIListDataSource(self, self._object_store_creator) | 92 return APIListDataSource(self, self._object_store_creator) |
92 | 93 |
93 def __init__(self, factory, object_store_creator): | 94 def __init__(self, factory, object_store_creator): |
94 self._factory = factory | 95 self._factory = factory |
95 self._object_store = object_store_creator.Create(APIListDataSource) | 96 self._object_store = object_store_creator.Create(APIListDataSource) |
96 | 97 |
97 def _GetCachedAPIData(self): | 98 def _GetCachedAPIData(self): |
98 data = self._object_store.Get('api_data').Get() | 99 data = self._object_store.Get('api_data').Get() |
99 if data is None: | 100 if data is None: |
100 data = self._factory._GenerateAPIDict() | 101 data = self._factory._GenerateAPIDict() |
101 self._object_store.Set('api_data', data) | 102 self._object_store.Set('api_data', data) |
102 return data | 103 return data |
103 | 104 |
104 def get(self, key): | 105 def get(self, key): |
105 return self._GetCachedAPIData().get(key) | 106 return self._GetCachedAPIData().get(key) |
OLD | NEW |