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 file_system import FileNotFoundError | 5 from file_system import FileNotFoundError |
6 import logging | 6 import logging |
7 import object_store | 7 import object_store |
8 import string | 8 import string |
9 | 9 |
10 def _ClassifySchemaNode(node_name, api): | 10 def _ClassifySchemaNode(node_name, api): |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 self._api_data_source_factory.Create(None, disable_refs=True), | 60 self._api_data_source_factory.Create(None, disable_refs=True), |
61 self._api_list_data_source_factory.Create(), | 61 self._api_list_data_source_factory.Create(), |
62 self._object_store) | 62 self._object_store) |
63 | 63 |
64 def __init__(self, api_data_source, api_list_data_source, object_store): | 64 def __init__(self, api_data_source, api_list_data_source, object_store): |
65 self._api_data_source = api_data_source | 65 self._api_data_source = api_data_source |
66 self._api_list_data_source = api_list_data_source | 66 self._api_list_data_source = api_list_data_source |
67 self._object_store = object_store | 67 self._object_store = object_store |
68 | 68 |
69 def _GetRefLink(self, ref, api_list, namespace, title): | 69 def _GetRefLink(self, ref, api_list, namespace, title): |
70 # Easy: maybe it's just a ref to an API. | |
71 if ref in api_list: | |
Jeffrey Yasskin
2013/01/18 18:27:31
Are the elements of api_list like "tabs" or "chrom
not at google - send to devlin
2013/01/18 18:30:25
They're just like "tabs". There's no need for "chr
| |
72 return { | |
73 'href': '%s.html' % ref, | |
74 'text': title if title else ref, | |
75 'name': ref | |
76 } | |
77 | |
78 # Harder: maybe it's a ref to a node within an API. | |
70 parts = ref.split('.') | 79 parts = ref.split('.') |
71 for i, part in enumerate(parts): | 80 for i, part in enumerate(parts): |
72 api_name = '.'.join(parts[:i]) | 81 api_name = '.'.join(parts[:i]) |
73 if api_name not in api_list: | 82 if api_name not in api_list: |
74 continue | 83 continue |
75 try: | 84 try: |
76 api = self._api_data_source.get(api_name) | 85 api = self._api_data_source.get(api_name) |
77 except FileNotFoundError: | 86 except FileNotFoundError: |
78 continue | 87 continue |
79 name = '.'.join(parts[i:]) | 88 name = '.'.join(parts[i:]) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 index += 1 | 189 index += 1 |
181 rest = '%s%s' % (ref[index:], rest) | 190 rest = '%s%s' % (ref[index:], rest) |
182 ref = ref[:index] | 191 ref = ref[:index] |
183 while not ref[-1].isalnum(): | 192 while not ref[-1].isalnum(): |
184 rest = '%s%s' % (ref[-1], rest) | 193 rest = '%s%s' % (ref[-1], rest) |
185 ref = ref[:-1] | 194 ref = ref[:-1] |
186 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) | 195 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) |
187 formatted_text.append('<a href="%(href)s">%(text)s</a>%(rest)s' % | 196 formatted_text.append('<a href="%(href)s">%(text)s</a>%(rest)s' % |
188 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest }) | 197 { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest }) |
189 return ''.join(formatted_text) | 198 return ''.join(formatted_text) |
OLD | NEW |