| 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 import os | 6 import os |
| 7 | 7 |
| 8 from branch_utility import BranchUtility | 8 from branch_utility import BranchUtility |
| 9 from docs_server_utils import FormatKey | 9 from docs_server_utils import FormatKey |
| 10 import compiled_file_system as compiled_fs | 10 import compiled_file_system as compiled_fs |
| 11 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
| 12 from third_party.handlebar import Handlebar | 12 from third_party.handlebar import Handlebar |
| 13 import url_constants | 13 import url_constants |
| 14 | 14 |
| 15 # Increment this if the data model changes for TemplateDataSource. | |
| 16 _VERSION = 3 | |
| 17 | |
| 18 EXTENSIONS_URL = '/chrome/extensions' | 15 EXTENSIONS_URL = '/chrome/extensions' |
| 19 | 16 |
| 20 def _MakeChannelDict(channel_name): | 17 def _MakeChannelDict(channel_name): |
| 21 channel_dict = { | 18 channel_dict = { |
| 22 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()], | 19 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()], |
| 23 'current': channel_name | 20 'current': channel_name |
| 24 } | 21 } |
| 25 for channel in channel_dict['channels']: | 22 for channel in channel_dict['channels']: |
| 26 if channel['name'] == channel_name: | 23 if channel['name'] == channel_name: |
| 27 channel['isCurrent'] = True | 24 channel['isCurrent'] = True |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 ref_resolver_factory, | 51 ref_resolver_factory, |
| 55 public_template_path, | 52 public_template_path, |
| 56 private_template_path): | 53 private_template_path): |
| 57 self._branch_info = _MakeChannelDict(channel_name) | 54 self._branch_info = _MakeChannelDict(channel_name) |
| 58 self._api_data_source_factory = api_data_source_factory | 55 self._api_data_source_factory = api_data_source_factory |
| 59 self._api_list_data_source_factory = api_list_data_source_factory | 56 self._api_list_data_source_factory = api_list_data_source_factory |
| 60 self._intro_data_source_factory = intro_data_source_factory | 57 self._intro_data_source_factory = intro_data_source_factory |
| 61 self._samples_data_source_factory = samples_data_source_factory | 58 self._samples_data_source_factory = samples_data_source_factory |
| 62 self._sidenav_data_source_factory = sidenav_data_source_factory | 59 self._sidenav_data_source_factory = sidenav_data_source_factory |
| 63 self._cache = compiled_fs_factory.Create(self._CreateTemplate, | 60 self._cache = compiled_fs_factory.Create(self._CreateTemplate, |
| 64 TemplateDataSource, | 61 TemplateDataSource) |
| 65 version=_VERSION) | |
| 66 self._ref_resolver = ref_resolver_factory.Create() | 62 self._ref_resolver = ref_resolver_factory.Create() |
| 67 self._public_template_path = public_template_path | 63 self._public_template_path = public_template_path |
| 68 self._private_template_path = private_template_path | 64 self._private_template_path = private_template_path |
| 69 self._static_resources = '/%s/static' % channel_name | 65 self._static_resources = '/%s/static' % channel_name |
| 70 | 66 |
| 71 def _CreateTemplate(self, template_name, text): | 67 def _CreateTemplate(self, template_name, text): |
| 72 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) | 68 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) |
| 73 | 69 |
| 74 def Create(self, request, path): | 70 def Create(self, request, path): |
| 75 """Returns a new TemplateDataSource bound to |request|. | 71 """Returns a new TemplateDataSource bound to |request|. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 def get(self, key): | 139 def get(self, key): |
| 144 return self.GetTemplate(self._private_template_path, key) | 140 return self.GetTemplate(self._private_template_path, key) |
| 145 | 141 |
| 146 def GetTemplate(self, base_path, template_name): | 142 def GetTemplate(self, base_path, template_name): |
| 147 try: | 143 try: |
| 148 return self._cache.GetFromFile( | 144 return self._cache.GetFromFile( |
| 149 '/'.join((base_path, FormatKey(template_name)))) | 145 '/'.join((base_path, FormatKey(template_name)))) |
| 150 except FileNotFoundError as e: | 146 except FileNotFoundError as e: |
| 151 logging.error(e) | 147 logging.error(e) |
| 152 return None | 148 return None |
| OLD | NEW |