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 import os | 6 import os |
| 7 import traceback | 7 import traceback |
| 8 | 8 |
| 9 from branch_utility import BranchUtility | 9 from branch_utility import BranchUtility |
| 10 import compiled_file_system as compiled_fs | 10 import compiled_file_system as compiled_fs |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 def __init__(self, | 44 def __init__(self, |
| 45 channel_name, | 45 channel_name, |
| 46 api_data_source_factory, | 46 api_data_source_factory, |
| 47 api_list_data_source_factory, | 47 api_list_data_source_factory, |
| 48 intro_data_source_factory, | 48 intro_data_source_factory, |
| 49 samples_data_source_factory, | 49 samples_data_source_factory, |
| 50 sidenav_data_source_factory, | 50 sidenav_data_source_factory, |
| 51 compiled_fs_factory, | 51 compiled_fs_factory, |
| 52 ref_resolver_factory, | 52 ref_resolver_factory, |
| 53 public_template_path, | 53 public_template_path, |
| 54 private_template_path): | 54 private_template_path, |
| 55 branch_path=None): | |
| 55 self._branch_info = _MakeChannelDict(channel_name) | 56 self._branch_info = _MakeChannelDict(channel_name) |
| 56 self._api_data_source_factory = api_data_source_factory | 57 self._api_data_source_factory = api_data_source_factory |
| 57 self._api_list_data_source_factory = api_list_data_source_factory | 58 self._api_list_data_source_factory = api_list_data_source_factory |
| 58 self._intro_data_source_factory = intro_data_source_factory | 59 self._intro_data_source_factory = intro_data_source_factory |
| 59 self._samples_data_source_factory = samples_data_source_factory | 60 self._samples_data_source_factory = samples_data_source_factory |
| 60 self._sidenav_data_source_factory = sidenav_data_source_factory | 61 self._sidenav_data_source_factory = sidenav_data_source_factory |
| 61 self._cache = compiled_fs_factory.Create(self._CreateTemplate, | 62 self._cache = compiled_fs_factory.Create(self._CreateTemplate, |
| 62 TemplateDataSource) | 63 TemplateDataSource) |
| 63 self._ref_resolver = ref_resolver_factory.Create() | 64 self._ref_resolver = ref_resolver_factory.Create() |
| 64 self._public_template_path = public_template_path | 65 self._public_template_path = public_template_path |
| 65 self._private_template_path = private_template_path | 66 self._private_template_path = private_template_path |
| 66 self._static_resources = '/%s/static' % channel_name | 67 if branch_path is None: |
| 68 branch_path = '/' + channel_name | |
| 69 self._static_resources = '%s/static' % branch_path | |
|
not at google - send to devlin
2013/04/30 15:37:42
let's just pass in the static path directly rather
方觉(Fang Jue)
2013/05/02 15:29:16
I renamed it to base_path (and make it end with '/
| |
| 67 | 70 |
| 68 def _CreateTemplate(self, template_name, text): | 71 def _CreateTemplate(self, template_name, text): |
| 69 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) | 72 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) |
| 70 | 73 |
| 71 def Create(self, request, path): | 74 def Create(self, request, path): |
| 72 """Returns a new TemplateDataSource bound to |request|. | 75 """Returns a new TemplateDataSource bound to |request|. |
| 73 """ | 76 """ |
| 74 return TemplateDataSource( | 77 return TemplateDataSource( |
| 75 self._branch_info, | 78 self._branch_info, |
| 76 self._api_data_source_factory.Create(request), | 79 self._api_data_source_factory.Create(request), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 def get(self, key): | 143 def get(self, key): |
| 141 return self.GetTemplate(self._private_template_path, key) | 144 return self.GetTemplate(self._private_template_path, key) |
| 142 | 145 |
| 143 def GetTemplate(self, base_path, template_name): | 146 def GetTemplate(self, base_path, template_name): |
| 144 try: | 147 try: |
| 145 return self._cache.GetFromFile( | 148 return self._cache.GetFromFile( |
| 146 '/'.join((base_path, FormatKey(template_name)))) | 149 '/'.join((base_path, FormatKey(template_name)))) |
| 147 except FileNotFoundError as e: | 150 except FileNotFoundError as e: |
| 148 logging.warning(traceback.format_exc()) | 151 logging.warning(traceback.format_exc()) |
| 149 return None | 152 return None |
| OLD | NEW |