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 third_party.handlebar import Handlebar | 8 from third_party.handlebar import Handlebar |
9 from handlebar_dict_generator import NoDocError | |
9 | 10 |
10 EXTENSIONS_URL = '/chrome/extensions' | 11 EXTENSIONS_URL = '/chrome/extensions' |
11 | 12 |
12 def _MakeBranchDict(branch): | 13 def _MakeBranchDict(branch): |
13 return { | 14 return { |
14 'showWarning': branch != 'stable', | 15 'showWarning': branch != 'stable', |
15 'branches': [ | 16 'branches': [ |
16 { 'name': 'Stable', 'path': 'stable' }, | 17 { 'name': 'Stable', 'path': 'stable' }, |
17 { 'name': 'Dev', 'path': 'dev' }, | 18 { 'name': 'Dev', 'path': 'dev' }, |
18 { 'name': 'Beta', 'path': 'beta' }, | 19 { 'name': 'Beta', 'path': 'beta' }, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 97 |
97 def Render(self, template_name): | 98 def Render(self, template_name): |
98 """This method will render a template named |template_name|, fetching all | 99 """This method will render a template named |template_name|, fetching all |
99 the partial templates needed from |self._cache|. Partials are retrieved | 100 the partial templates needed from |self._cache|. Partials are retrieved |
100 from the TemplateDataSource with the |get| method. | 101 from the TemplateDataSource with the |get| method. |
101 """ | 102 """ |
102 template = self.GetTemplate(self._public_template_path, template_name) | 103 template = self.GetTemplate(self._public_template_path, template_name) |
103 if not template: | 104 if not template: |
104 return '' | 105 return '' |
105 # TODO error handling | 106 # TODO error handling |
106 return template.render({ | 107 try: |
107 'api_list': self._api_list_data_source, | 108 return template.render({ |
108 'apis': self._api_data_source, | 109 'api_list': self._api_list_data_source, |
109 'branchInfo': self._branch_info, | 110 'apis': self._api_data_source, |
110 'intros': self._intro_data_source, | 111 'branchInfo': self._branch_info, |
111 'partials': self, | 112 'intros': self._intro_data_source, |
112 'samples': self._samples_data_source, | 113 'partials': self, |
113 'static': self._static_resources, | 114 'samples': self._samples_data_source, |
114 'true': True, | 115 'static': self._static_resources, |
115 'false': False | 116 'true': True, |
116 }).text | 117 'false': False |
118 }).text | |
119 except NoDocError: | |
120 return '' | |
not at google - send to devlin
2012/08/09 05:11:36
See comment in handlebar_dict_generator.py. This f
cduvall
2012/08/09 17:54:05
Done.
| |
117 | 121 |
118 def __getitem__(self, key): | 122 def __getitem__(self, key): |
119 return self.get(key) | 123 return self.get(key) |
120 | 124 |
121 def get(self, key): | 125 def get(self, key): |
122 return self.GetTemplate(self._private_template_path, key) | 126 return self.GetTemplate(self._private_template_path, key) |
123 | 127 |
124 def GetTemplate(self, base_path, template_name): | 128 def GetTemplate(self, base_path, template_name): |
125 real_path = FormatKey(template_name) | 129 real_path = FormatKey(template_name) |
126 try: | 130 try: |
127 return self._cache.GetFromFile(base_path + '/' + real_path) | 131 return self._cache.GetFromFile(base_path + '/' + real_path) |
128 except Exception as e: | 132 except Exception as e: |
129 logging.error(e) | 133 logging.error(e) |
130 return None | 134 return None |
OLD | NEW |