Chromium Code Reviews| 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'].upper(), | |
| 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() |
| 68 self._public_template_path = public_template_path | 76 self._public_template_path = public_template_path |
| 69 self._private_template_path = private_template_path | 77 self._private_template_path = private_template_path |
| 70 self._static_resources = '/%s/static' % channel_name | 78 self._static_resources = '/%s/static' % channel_name |
| 71 | 79 |
| 72 def _CreateTemplate(self, template_name, text): | 80 def _CreateTemplate(self, template_name, text): |
| 73 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) | 81 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) |
| 74 | 82 |
| 75 def Create(self, request, path): | 83 def Create(self, request, path): |
| 76 """Returns a new TemplateDataSource bound to |request|. | 84 """Returns a new TemplateDataSource bound to |request|. |
| 77 """ | 85 """ |
| 86 #branch_info = self._branch_info.copy() | |
|
cduvall
2013/03/25 22:59:43
take out?
epeterson
2013/03/27 22:36:09
Done.
| |
| 78 return TemplateDataSource( | 87 return TemplateDataSource( |
| 79 self._branch_info, | 88 self._branch_info, |
| 80 self._api_data_source_factory.Create(request), | 89 self._api_data_source_factory.Create(request), |
| 81 self._api_list_data_source_factory.Create(), | 90 self._api_list_data_source_factory.Create(), |
| 82 self._intro_data_source_factory.Create(), | 91 self._intro_data_source_factory.Create(), |
| 83 self._samples_data_source_factory.Create(request), | 92 self._samples_data_source_factory.Create(request), |
| 84 self._known_issues_data_source, | 93 self._known_issues_data_source, |
| 85 self._sidenav_data_source_factory.Create(path), | 94 self._sidenav_data_source_factory.Create(path), |
| 86 self._cache, | 95 self._cache, |
| 87 self._public_template_path, | 96 self._public_template_path, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 def get(self, key): | 160 def get(self, key): |
| 152 return self.GetTemplate(self._private_template_path, key) | 161 return self.GetTemplate(self._private_template_path, key) |
| 153 | 162 |
| 154 def GetTemplate(self, base_path, template_name): | 163 def GetTemplate(self, base_path, template_name): |
| 155 real_path = FormatKey(template_name) | 164 real_path = FormatKey(template_name) |
| 156 try: | 165 try: |
| 157 return self._cache.GetFromFile(base_path + '/' + real_path) | 166 return self._cache.GetFromFile(base_path + '/' + real_path) |
| 158 except FileNotFoundError as e: | 167 except FileNotFoundError as e: |
| 159 logging.info(e) | 168 logging.info(e) |
| 160 return None | 169 return None |
| OLD | NEW |