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

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

Issue 56083005: Docserver: Cleanup to remove the APIListDataSource dependency from (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 file_system import FileNotFoundError 5 from file_system import FileNotFoundError
6 import logging 6 import logging
7 import re 7 import re
8 import string 8 import string
9 9
10 def _ClassifySchemaNode(node_name, api): 10 def _ClassifySchemaNode(node_name, api):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 $ref:[api.node The Title] - Same as the previous form but title is set to 44 $ref:[api.node The Title] - Same as the previous form but title is set to
45 "The Title". 45 "The Title".
46 """ 46 """
47 47
48 # Matches after a $ref: that doesn't have []s. 48 # Matches after a $ref: that doesn't have []s.
49 _bare_ref = re.compile('\w+(\.\w+)*') 49 _bare_ref = re.compile('\w+(\.\w+)*')
50 50
51 class Factory(object): 51 class Factory(object):
52 def __init__(self, 52 def __init__(self,
53 api_data_source_factory, 53 api_data_source_factory,
54 api_list_data_source_factory, 54 api_models,
55 object_store_creator): 55 object_store_creator):
56 self._api_data_source_factory = api_data_source_factory 56 self._api_data_source_factory = api_data_source_factory
57 self._api_list_data_source_factory = api_list_data_source_factory 57 self._api_models = api_models
58 self._object_store_creator = object_store_creator 58 self._object_store_creator = object_store_creator
59 59
60 def Create(self): 60 def Create(self):
61 return ReferenceResolver( 61 return ReferenceResolver(
62 self._api_data_source_factory.Create(None), 62 self._api_data_source_factory.Create(None),
63 self._api_list_data_source_factory.Create(), 63 self._api_models,
64 self._object_store_creator.Create(ReferenceResolver)) 64 self._object_store_creator.Create(ReferenceResolver))
65 65
66 def __init__(self, api_data_source, api_list_data_source, object_store): 66 def __init__(self, api_data_source, api_models, object_store):
67 self._api_data_source = api_data_source 67 self._api_data_source = api_data_source
68 self._api_list_data_source = api_list_data_source 68 self._api_models = api_models
69 self._object_store = object_store 69 self._object_store = object_store
70 70
71 def _GetRefLink(self, ref, api_list, namespace, title): 71 def _GetRefLink(self, ref, api_list, namespace, title):
72 # Check nodes within each API the ref might refer to. 72 # Check nodes within each API the ref might refer to.
73 parts = ref.split('.') 73 parts = ref.split('.')
74 for i, part in enumerate(parts): 74 for i, part in enumerate(parts):
75 api_name = '.'.join(parts[:i]) 75 api_name = '.'.join(parts[:i])
76 if api_name not in api_list: 76 if api_name not in api_list:
77 continue 77 continue
78 try: 78 try:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return None 121 return None
122 122
123 def GetLink(self, ref, namespace=None, title=None): 123 def GetLink(self, ref, namespace=None, title=None):
124 """Resolve $ref |ref| in namespace |namespace| if not None, returning None 124 """Resolve $ref |ref| in namespace |namespace| if not None, returning None
125 if it cannot be resolved. 125 if it cannot be resolved.
126 """ 126 """
127 link = self._object_store.Get(_MakeKey(namespace, ref, title)).Get() 127 link = self._object_store.Get(_MakeKey(namespace, ref, title)).Get()
128 if link is not None: 128 if link is not None:
129 return link 129 return link
130 130
131 api_list = self._api_list_data_source.GetAllNames() 131 api_list = self._api_models.GetNames()
132 link = self._GetRefLink(ref, api_list, namespace, title) 132 link = self._GetRefLink(ref, api_list, namespace, title)
133 133
134 if link is None and namespace is not None: 134 if link is None and namespace is not None:
135 # Try to resolve the ref in the current namespace if there is one. 135 # Try to resolve the ref in the current namespace if there is one.
136 link = self._GetRefLink('%s.%s' % (namespace, ref), 136 link = self._GetRefLink('%s.%s' % (namespace, ref),
137 api_list, 137 api_list,
138 namespace, 138 namespace,
139 title) 139 title)
140 140
141 if link is not None: 141 if link is not None:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ref = '' 188 ref = ''
189 rest = ref_and_rest 189 rest = ref_and_rest
190 else: 190 else:
191 ref = match.group() 191 ref = match.group()
192 rest = ref_and_rest[match.end():] 192 rest = ref_and_rest[match.end():]
193 193
194 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) 194 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title)
195 formatted_text.append('<a href="%(href)s">%(text)s</a>%(rest)s' % 195 formatted_text.append('<a href="%(href)s">%(text)s</a>%(rest)s' %
196 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest }) 196 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest })
197 return ''.join(formatted_text) 197 return ''.join(formatted_text)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/cron.yaml ('k') | chrome/common/extensions/docs/server2/reference_resolver_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698