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 copy import deepcopy | 5 from copy import deepcopy |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 $ref:api.node - Replaces the $ref with a link to node on the API page. The | 53 $ref:api.node - Replaces the $ref with a link to node on the API page. The |
54 title is set to the name of the node. | 54 title is set to the name of the node. |
55 | 55 |
56 $ref:[api.node The Title] - Same as the previous form but title is set to | 56 $ref:[api.node The Title] - Same as the previous form but title is set to |
57 "The Title". | 57 "The Title". |
58 """ | 58 """ |
59 | 59 |
60 # Matches after a $ref: that doesn't have []s. | 60 # Matches after a $ref: that doesn't have []s. |
61 _bare_ref = re.compile('\w+(\.\w+)*') | 61 _bare_ref = re.compile('\w+(\.\w+)*') |
62 | 62 |
63 class Factory(object): | |
64 def __init__(self, | |
65 api_data_source_factory, | |
66 api_models, | |
67 object_store_creator): | |
68 self._api_data_source_factory = api_data_source_factory | |
69 self._api_models = api_models | |
70 self._object_store_creator = object_store_creator | |
71 | |
72 def Create(self): | |
73 return ReferenceResolver( | |
74 self._api_data_source_factory.Create(None), | |
75 self._api_models, | |
76 self._object_store_creator.Create(ReferenceResolver)) | |
77 | |
78 def __init__(self, api_data_source, api_models, object_store): | 63 def __init__(self, api_data_source, api_models, object_store): |
79 self._api_data_source = api_data_source | 64 self._api_data_source = api_data_source |
80 self._api_models = api_models | 65 self._api_models = api_models |
81 self._object_store = object_store | 66 self._object_store = object_store |
82 | 67 |
83 def _GetRefLink(self, ref, api_list, namespace): | 68 def _GetRefLink(self, ref, api_list, namespace): |
84 # Check nodes within each API the ref might refer to. | 69 # Check nodes within each API the ref might refer to. |
85 parts = ref.split('.') | 70 parts = ref.split('.') |
86 for i, part in enumerate(parts): | 71 for i, part in enumerate(parts): |
87 api_name = '.'.join(parts[:i]) | 72 api_name = '.'.join(parts[:i]) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ref = '' | 195 ref = '' |
211 rest = ref_and_rest | 196 rest = ref_and_rest |
212 else: | 197 else: |
213 ref = match.group() | 198 ref = match.group() |
214 rest = ref_and_rest[match.end():] | 199 rest = ref_and_rest[match.end():] |
215 | 200 |
216 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) | 201 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) |
217 formatted_text.append('<a href="%s%s">%s</a>%s' % | 202 formatted_text.append('<a href="%s%s">%s</a>%s' % |
218 (link_prefix, ref_dict['href'], ref_dict['text'], rest)) | 203 (link_prefix, ref_dict['href'], ref_dict['text'], rest)) |
219 return ''.join(formatted_text) | 204 return ''.join(formatted_text) |
OLD | NEW |