| 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 import compiled_file_system as compiled_fs | 9 import compiled_file_system as compiled_fs |
| 10 from docs_server_utils import FormatKey | 10 from docs_server_utils import FormatKey |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 self._public_template_path = public_template_path | 104 self._public_template_path = public_template_path |
| 105 self._private_template_path = private_template_path | 105 self._private_template_path = private_template_path |
| 106 self._static_resources = static_resources | 106 self._static_resources = static_resources |
| 107 | 107 |
| 108 def Render(self, template_name): | 108 def Render(self, template_name): |
| 109 """This method will render a template named |template_name|, fetching all | 109 """This method will render a template named |template_name|, fetching all |
| 110 the partial templates needed from |self._cache|. Partials are retrieved | 110 the partial templates needed from |self._cache|. Partials are retrieved |
| 111 from the TemplateDataSource with the |get| method. | 111 from the TemplateDataSource with the |get| method. |
| 112 """ | 112 """ |
| 113 template = self.GetTemplate(self._public_template_path, template_name) | 113 template = self.GetTemplate(self._public_template_path, template_name) |
| 114 if not template: | 114 if template is None: |
| 115 return None | 115 return None |
| 116 # TODO error handling | 116 # TODO error handling |
| 117 render_data = template.render({ | 117 render_data = template.render({ |
| 118 'api_list': self._api_list_data_source, | 118 'api_list': self._api_list_data_source, |
| 119 'apis': self._api_data_source, | 119 'apis': self._api_data_source, |
| 120 'branchInfo': self._branch_info, | 120 'branchInfo': self._branch_info, |
| 121 'intros': self._intro_data_source, | 121 'intros': self._intro_data_source, |
| 122 'sidenavs': self._sidenav_data_source, | 122 'sidenavs': self._sidenav_data_source, |
| 123 'partials': self, | 123 'partials': self, |
| 124 'samples': self._samples_data_source, | 124 'samples': self._samples_data_source, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 | 144 |
| 145 def get(self, key): | 145 def get(self, key): |
| 146 return self.GetTemplate(self._private_template_path, key) | 146 return self.GetTemplate(self._private_template_path, key) |
| 147 | 147 |
| 148 def GetTemplate(self, base_path, template_name): | 148 def GetTemplate(self, base_path, template_name): |
| 149 try: | 149 try: |
| 150 return self._cache.GetFromFile( | 150 return self._cache.GetFromFile( |
| 151 '/'.join((base_path, FormatKey(template_name)))) | 151 '/'.join((base_path, FormatKey(template_name)))) |
| 152 except FileNotFoundError as e: | 152 except FileNotFoundError as e: |
| 153 return None | 153 return None |
| OLD | NEW |