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 import logging | 5 import logging |
6 | 6 |
7 from branch_utility import BranchUtility | 7 from branch_utility import BranchUtility |
8 from docs_server_utils import FormatKey | 8 from docs_server_utils import FormatKey |
9 import compiled_file_system as compiled_fs | 9 import compiled_file_system as compiled_fs |
10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
11 from third_party.handlebar import Handlebar | 11 from third_party.handlebar import Handlebar |
12 import url_constants | 12 import url_constants |
13 | 13 |
14 # Increment this if there are changes to the data stored about templates. | 14 # Increment this if there are changes to the data stored about templates. |
15 _VERSION = 2 | 15 _VERSION = 2 |
16 | 16 |
17 EXTENSIONS_URL = '/chrome/extensions' | 17 EXTENSIONS_URL = '/chrome/extensions' |
18 | 18 |
19 def _MakeChannelDict(channel_name): | 19 def _MakeChannelDict(channel_name, all_channels): |
20 channel_dict = { | 20 return { |
21 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()], | 21 'channels' : [ |
| 22 { |
| 23 'name': channel['name'], |
| 24 'version': channel['version'], |
| 25 'path': channel['name'], |
| 26 'isCurrent': channel['name'] == channel_name |
| 27 } for channel in all_channels |
| 28 ], |
22 'current': channel_name | 29 'current': channel_name |
23 } | 30 } |
24 for channel in channel_dict['channels']: | 31 for channel in channel_dict['channels']: |
25 if channel['name'] == channel_name: | 32 if channel['name'] == channel_name: |
26 channel['isCurrent'] = True | 33 channel['isCurrent'] = True |
27 return channel_dict | 34 return channel_dict |
28 | 35 |
29 class TemplateDataSource(object): | 36 class TemplateDataSource(object): |
30 """Renders Handlebar templates, providing them with the context in which to | 37 """Renders Handlebar templates, providing them with the context in which to |
31 render. | 38 render. |
(...skipping 14 matching lines...) Expand all Loading... |
46 channel_name, | 53 channel_name, |
47 api_data_source_factory, | 54 api_data_source_factory, |
48 api_list_data_source_factory, | 55 api_list_data_source_factory, |
49 intro_data_source_factory, | 56 intro_data_source_factory, |
50 samples_data_source_factory, | 57 samples_data_source_factory, |
51 known_issues_data_source, | 58 known_issues_data_source, |
52 sidenav_data_source_factory, | 59 sidenav_data_source_factory, |
53 cache_factory, | 60 cache_factory, |
54 ref_resolver_factory, | 61 ref_resolver_factory, |
55 public_template_path, | 62 public_template_path, |
56 private_template_path): | 63 private_template_path, |
57 self._branch_info = _MakeChannelDict(channel_name) | 64 all_channels): |
| 65 self._branch_info = _MakeChannelDict(channel_name, all_channels) |
58 self._api_data_source_factory = api_data_source_factory | 66 self._api_data_source_factory = api_data_source_factory |
59 self._api_list_data_source_factory = api_list_data_source_factory | 67 self._api_list_data_source_factory = api_list_data_source_factory |
60 self._intro_data_source_factory = intro_data_source_factory | 68 self._intro_data_source_factory = intro_data_source_factory |
61 self._samples_data_source_factory = samples_data_source_factory | 69 self._samples_data_source_factory = samples_data_source_factory |
62 self._known_issues_data_source = known_issues_data_source | 70 self._known_issues_data_source = known_issues_data_source |
63 self._sidenav_data_source_factory = sidenav_data_source_factory | 71 self._sidenav_data_source_factory = sidenav_data_source_factory |
64 self._cache = cache_factory.Create(self._CreateTemplate, | 72 self._cache = cache_factory.Create(self._CreateTemplate, |
65 compiled_fs.HANDLEBAR, | 73 compiled_fs.HANDLEBAR, |
66 version=_VERSION) | 74 version=_VERSION) |
67 self._ref_resolver = ref_resolver_factory.Create() | 75 self._ref_resolver = ref_resolver_factory.Create() |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 def get(self, key): | 159 def get(self, key): |
152 return self.GetTemplate(self._private_template_path, key) | 160 return self.GetTemplate(self._private_template_path, key) |
153 | 161 |
154 def GetTemplate(self, base_path, template_name): | 162 def GetTemplate(self, base_path, template_name): |
155 real_path = FormatKey(template_name) | 163 real_path = FormatKey(template_name) |
156 try: | 164 try: |
157 return self._cache.GetFromFile(base_path + '/' + real_path) | 165 return self._cache.GetFromFile(base_path + '/' + real_path) |
158 except FileNotFoundError as e: | 166 except FileNotFoundError as e: |
159 logging.info(e) | 167 logging.info(e) |
160 return None | 168 return None |
OLD | NEW |