| 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 |
| 11 from docs_server_utils import FormatKey | 11 from docs_server_utils import FormatKey |
| 12 from file_system import FileNotFoundError | 12 from file_system import FileNotFoundError |
| 13 from third_party.handlebar import Handlebar | 13 from third_party.handlebar import Handlebar |
| 14 import url_constants | 14 import url_constants |
| 15 | 15 |
| 16 EXTENSIONS_URL = '/chrome/extensions' | 16 EXTENSIONS_URL = '/chrome/extensions' |
| 17 | 17 |
| 18 def _MakeChannelDict(channel_name): | 18 def _MakeChannelDict(channel_name): |
| 19 channel_dict = { | 19 channel_dict = { |
| 20 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()], | 20 'channels': [{'name': name} for name in BranchUtility.GetAllChannelNames()], |
| 21 'current': channel_name | 21 'current': channel_name |
| 22 } | 22 } |
| 23 for channel in channel_dict['channels']: | 23 for channel in channel_dict['channels']: |
| 24 if channel['name'] == channel_name: | 24 if channel['name'] == channel_name: |
| 25 channel['isCurrent'] = True | 25 channel['isCurrent'] = True |
| 26 return channel_dict | 26 return channel_dict |
| 27 | 27 |
| 28 class TemplateDataSource(object): | 28 class TemplateDataSource(object): |
| 29 """Renders Handlebar templates, providing them with the context in which to | 29 """Renders Handlebar templates, providing them with the context in which to |
| 30 render. | 30 render. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, |
| 125 'static': self._static_resources, | 125 'static': self._static_resources, |
| 126 'app': 'app', | 126 'app': 'app', |
| 127 'extension': 'extension', | 127 'extension': 'extension', |
| 128 'apps_title': 'Apps', | 128 'apps_title': 'Apps', |
| 129 'extensions_title': 'Extensions', | 129 'extensions_title': 'Extensions', |
| 130 'apps_samples_url': url_constants.GITHUB_BASE, | 130 'apps_samples_url': url_constants.GITHUB_BASE, |
| 131 # TODO(kalman): this is wrong, it's always getting from trunk, but meh |
| 132 # it hardly ever shows up (only in the "cannot fetch samples" message). |
| 133 # In fact I don't even know if it can show up anymore due the samples data |
| 134 # being persisent. In any case, when the channel distinctions are gone |
| 135 # this can go away, so, double meh. |
| 131 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES, | 136 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES, |
| 132 'true': True, | 137 'true': True, |
| 133 'false': False | 138 'false': False |
| 134 }) | 139 }) |
| 135 if render_data.errors: | 140 if render_data.errors: |
| 136 logging.error('Handlebar error(s) rendering %s:\n%s' % | 141 logging.error('Handlebar error(s) rendering %s:\n%s' % |
| 137 (template_name, ' \n'.join(render_data.errors))) | 142 (template_name, ' \n'.join(render_data.errors))) |
| 138 return render_data.text | 143 return render_data.text |
| 139 | 144 |
| 140 def get(self, key): | 145 def get(self, key): |
| 141 return self.GetTemplate(self._private_template_path, key) | 146 return self.GetTemplate(self._private_template_path, key) |
| 142 | 147 |
| 143 def GetTemplate(self, base_path, template_name): | 148 def GetTemplate(self, base_path, template_name): |
| 144 try: | 149 try: |
| 145 return self._cache.GetFromFile( | 150 return self._cache.GetFromFile( |
| 146 '/'.join((base_path, FormatKey(template_name)))) | 151 '/'.join((base_path, FormatKey(template_name)))) |
| 147 except FileNotFoundError as e: | 152 except FileNotFoundError as e: |
| 148 logging.warning(traceback.format_exc()) | 153 logging.warning(traceback.format_exc()) |
| 149 return None | 154 return None |
| OLD | NEW |