| 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 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
| 10 from third_party.handlebar import Handlebar | 10 from third_party.handlebar import Handlebar |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 self._public_template_path = public_template_path | 112 self._public_template_path = public_template_path |
| 113 self._private_template_path = private_template_path | 113 self._private_template_path = private_template_path |
| 114 self._static_resources = static_resources | 114 self._static_resources = static_resources |
| 115 | 115 |
| 116 def Render(self, template_name): | 116 def Render(self, template_name): |
| 117 """This method will render a template named |template_name|, fetching all | 117 """This method will render a template named |template_name|, fetching all |
| 118 the partial templates needed from |self._cache|. Partials are retrieved | 118 the partial templates needed from |self._cache|. Partials are retrieved |
| 119 from the TemplateDataSource with the |get| method. | 119 from the TemplateDataSource with the |get| method. |
| 120 """ | 120 """ |
| 121 template = self.GetTemplate(self._public_template_path, template_name) | 121 template = self.GetTemplate(self._public_template_path, template_name) |
| 122 if not template: | 122 if template is None: |
| 123 return None | 123 return None |
| 124 # TODO error handling | 124 # TODO error handling |
| 125 render_data = template.render({ | 125 render_data = template.render({ |
| 126 'api_list': self._api_list_data_source, | 126 'api_list': self._api_list_data_source, |
| 127 'apis': self._api_data_source, | 127 'apis': self._api_data_source, |
| 128 'branchInfo': self._branch_info, | 128 'branchInfo': self._branch_info, |
| 129 'intros': self._intro_data_source, | 129 'intros': self._intro_data_source, |
| 130 'sidenavs': self._sidenav_data_source, | 130 'sidenavs': self._sidenav_data_source, |
| 131 'partials': self, | 131 'partials': self, |
| 132 'samples': self._samples_data_source, | 132 'samples': self._samples_data_source, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 | 149 |
| 150 def get(self, key): | 150 def get(self, key): |
| 151 return self.GetTemplate(self._private_template_path, key) | 151 return self.GetTemplate(self._private_template_path, key) |
| 152 | 152 |
| 153 def GetTemplate(self, base_path, template_name): | 153 def GetTemplate(self, base_path, template_name): |
| 154 try: | 154 try: |
| 155 return self._cache.GetFromFile( | 155 return self._cache.GetFromFile( |
| 156 '/'.join((base_path, FormatKey(template_name)))) | 156 '/'.join((base_path, FormatKey(template_name)))) |
| 157 except FileNotFoundError as e: | 157 except FileNotFoundError as e: |
| 158 return None | 158 return None |
| OLD | NEW |