| 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 docs_server_utils import FormatKey | 7 from docs_server_utils import FormatKey |
| 8 from file_system import FileNotFoundError | 8 from file_system import FileNotFoundError |
| 9 import file_system_cache as fs_cache |
| 9 from third_party.handlebar import Handlebar | 10 from third_party.handlebar import Handlebar |
| 10 | 11 |
| 11 EXTENSIONS_URL = '/chrome/extensions' | 12 EXTENSIONS_URL = '/chrome/extensions' |
| 12 | 13 |
| 13 def _MakeChannelDict(channel_name): | 14 def _MakeChannelDict(channel_name): |
| 14 return { | 15 return { |
| 15 'showWarning': channel_name != 'stable', | 16 'showWarning': channel_name != 'stable', |
| 16 'channels': [ | 17 'channels': [ |
| 17 { 'name': 'Stable', 'path': 'stable' }, | 18 { 'name': 'Stable', 'path': 'stable' }, |
| 18 { 'name': 'Dev', 'path': 'dev' }, | 19 { 'name': 'Dev', 'path': 'dev' }, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 a Factory to cheaply construct these. | 35 a Factory to cheaply construct these. |
| 35 """ | 36 """ |
| 36 | 37 |
| 37 class Factory(object): | 38 class Factory(object): |
| 38 """A factory to create lightweight TemplateDataSource instances bound to | 39 """A factory to create lightweight TemplateDataSource instances bound to |
| 39 individual Requests. | 40 individual Requests. |
| 40 """ | 41 """ |
| 41 def __init__(self, | 42 def __init__(self, |
| 42 channel_name, | 43 channel_name, |
| 43 api_data_source_factory, | 44 api_data_source_factory, |
| 44 api_list_data_source, | 45 api_list_data_source_factory, |
| 45 intro_data_source, | 46 intro_data_source_factory, |
| 46 samples_data_source_factory, | 47 samples_data_source_factory, |
| 47 cache_builder, | 48 cache_builder, |
| 48 public_template_path, | 49 public_template_path, |
| 49 private_template_path): | 50 private_template_path): |
| 50 self._branch_info = _MakeChannelDict(channel_name) | 51 self._branch_info = _MakeChannelDict(channel_name) |
| 51 self._api_data_source_factory = api_data_source_factory | 52 self._api_data_source_factory = api_data_source_factory |
| 52 self._api_list_data_source = api_list_data_source | 53 self._api_list_data_source_factory = api_list_data_source_factory |
| 53 self._intro_data_source = intro_data_source | 54 self._intro_data_source_factory = intro_data_source_factory |
| 54 self._samples_data_source_factory = samples_data_source_factory | 55 self._samples_data_source_factory = samples_data_source_factory |
| 55 self._cache = cache_builder.build(Handlebar) | 56 self._cache = cache_builder.build(Handlebar, fs_cache.FS_CACHE_HANDLEBAR) |
| 56 self._public_template_path = public_template_path | 57 self._public_template_path = public_template_path |
| 57 self._private_template_path = private_template_path | 58 self._private_template_path = private_template_path |
| 58 self._static_resources = ( | 59 self._static_resources = ( |
| 59 (('/' + channel_name) if channel_name != 'local' else '') + '/static') | 60 (('/' + channel_name) if channel_name != 'local' else '') + '/static') |
| 60 | 61 |
| 61 def Create(self, request): | 62 def Create(self, request): |
| 62 """Returns a new TemplateDataSource bound to |request|. | 63 """Returns a new TemplateDataSource bound to |request|. |
| 63 """ | 64 """ |
| 64 return TemplateDataSource( | 65 return TemplateDataSource( |
| 65 self._branch_info, | 66 self._branch_info, |
| 66 self._api_data_source_factory.Create(request), | 67 self._api_data_source_factory.Create(request), |
| 67 self._api_list_data_source, | 68 self._api_list_data_source_factory.Create(), |
| 68 self._intro_data_source, | 69 self._intro_data_source_factory.Create(), |
| 69 self._samples_data_source_factory.Create(request), | 70 self._samples_data_source_factory.Create(request), |
| 70 self._cache, | 71 self._cache, |
| 71 self._public_template_path, | 72 self._public_template_path, |
| 72 self._private_template_path, | 73 self._private_template_path, |
| 73 self._static_resources, | 74 self._static_resources, |
| 74 request) | 75 request) |
| 75 | 76 |
| 76 def __init__(self, | 77 def __init__(self, |
| 77 branch_info, | 78 branch_info, |
| 78 api_data_source, | 79 api_data_source, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 def get(self, key): | 125 def get(self, key): |
| 125 return self.GetTemplate(self._private_template_path, key) | 126 return self.GetTemplate(self._private_template_path, key) |
| 126 | 127 |
| 127 def GetTemplate(self, base_path, template_name): | 128 def GetTemplate(self, base_path, template_name): |
| 128 real_path = FormatKey(template_name) | 129 real_path = FormatKey(template_name) |
| 129 try: | 130 try: |
| 130 return self._cache.GetFromFile(base_path + '/' + real_path) | 131 return self._cache.GetFromFile(base_path + '/' + real_path) |
| 131 except FileNotFoundError as e: | 132 except FileNotFoundError as e: |
| 132 logging.error(e) | 133 logging.error(e) |
| 133 return None | 134 return None |
| OLD | NEW |