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 import compiled_file_system as compiled_fs | 8 import compiled_file_system as compiled_fs |
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 |
11 import url_constants | 11 import url_constants |
12 | 12 |
13 # Increment this if there are changes to the data stored about templates. | 13 # Increment this if there are changes to the data stored about templates. |
14 _VERSION = 1 | 14 _VERSION = 2 |
15 | 15 |
16 EXTENSIONS_URL = '/chrome/extensions' | 16 EXTENSIONS_URL = '/chrome/extensions' |
17 | 17 |
18 def _MakeChannelDict(channel_name): | 18 def _MakeChannelDict(channel_name, all_channels): |
19 return { | 19 return { |
20 'showWarning': channel_name != 'stable', | 20 'channels' : [{'name': channel['name'].upper(), |
cduvall
2013/03/21 18:43:53
reformat to:
'channels' : [
{
'name': ...
epeterson
2013/03/25 19:35:11
Done.
| |
21 'channels': [ | 21 'version': channel['version'], |
22 { 'name': 'Stable', 'path': 'stable' }, | 22 'path': channel['name'], |
23 { 'name': 'Dev', 'path': 'dev' }, | 23 'isCurrent': channel['name'] == channel_name} |
24 { 'name': 'Beta', 'path': 'beta' }, | 24 for channel in all_channels], |
25 { 'name': 'Trunk', 'path': 'trunk' } | |
26 ], | |
27 'current': channel_name | 25 'current': channel_name |
28 } | 26 } |
29 | 27 |
30 class TemplateDataSource(object): | 28 class TemplateDataSource(object): |
31 """Renders Handlebar templates, providing them with the context in which to | 29 """Renders Handlebar templates, providing them with the context in which to |
32 render. | 30 render. |
33 | 31 |
34 Also acts as a data source itself, providing partial Handlebar templates to | 32 Also acts as a data source itself, providing partial Handlebar templates to |
35 those it renders. | 33 those it renders. |
36 | 34 |
(...skipping 10 matching lines...) Expand all Loading... | |
47 channel_name, | 45 channel_name, |
48 api_data_source_factory, | 46 api_data_source_factory, |
49 api_list_data_source_factory, | 47 api_list_data_source_factory, |
50 intro_data_source_factory, | 48 intro_data_source_factory, |
51 samples_data_source_factory, | 49 samples_data_source_factory, |
52 known_issues_data_source, | 50 known_issues_data_source, |
53 sidenav_data_source_factory, | 51 sidenav_data_source_factory, |
54 cache_factory, | 52 cache_factory, |
55 ref_resolver_factory, | 53 ref_resolver_factory, |
56 public_template_path, | 54 public_template_path, |
57 private_template_path): | 55 private_template_path, |
58 self._branch_info = _MakeChannelDict(channel_name) | 56 all_channels): |
57 self._branch_info = _MakeChannelDict(channel_name, all_channels) | |
59 self._api_data_source_factory = api_data_source_factory | 58 self._api_data_source_factory = api_data_source_factory |
60 self._api_list_data_source_factory = api_list_data_source_factory | 59 self._api_list_data_source_factory = api_list_data_source_factory |
61 self._intro_data_source_factory = intro_data_source_factory | 60 self._intro_data_source_factory = intro_data_source_factory |
62 self._samples_data_source_factory = samples_data_source_factory | 61 self._samples_data_source_factory = samples_data_source_factory |
63 self._known_issues_data_source = known_issues_data_source | 62 self._known_issues_data_source = known_issues_data_source |
64 self._sidenav_data_source_factory = sidenav_data_source_factory | 63 self._sidenav_data_source_factory = sidenav_data_source_factory |
65 self._cache = cache_factory.Create(self._CreateTemplate, | 64 self._cache = cache_factory.Create(self._CreateTemplate, |
66 compiled_fs.HANDLEBAR, | 65 compiled_fs.HANDLEBAR, |
67 version=_VERSION) | 66 version=_VERSION) |
68 self._ref_resolver = ref_resolver_factory.Create() | 67 self._ref_resolver = ref_resolver_factory.Create() |
69 self._public_template_path = public_template_path | 68 self._public_template_path = public_template_path |
70 self._private_template_path = private_template_path | 69 self._private_template_path = private_template_path |
71 self._static_resources = '/%s/static' % channel_name | 70 self._static_resources = '/%s/static' % channel_name |
72 | 71 |
73 def _CreateTemplate(self, template_name, text): | 72 def _CreateTemplate(self, template_name, text): |
74 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) | 73 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) |
75 | 74 |
76 def Create(self, request, path): | 75 def Create(self, request, path): |
77 """Returns a new TemplateDataSource bound to |request|. | 76 """Returns a new TemplateDataSource bound to |request|. |
78 """ | 77 """ |
79 branch_info = self._branch_info.copy() | 78 branch_info = self._branch_info.copy() |
80 branch_info['showWarning'] = (not path.startswith('apps') and | |
81 branch_info['showWarning']) | |
82 return TemplateDataSource( | 79 return TemplateDataSource( |
83 branch_info, | 80 branch_info, |
84 self._api_data_source_factory.Create(request), | 81 self._api_data_source_factory.Create(request), |
85 self._api_list_data_source_factory.Create(), | 82 self._api_list_data_source_factory.Create(), |
86 self._intro_data_source_factory.Create(), | 83 self._intro_data_source_factory.Create(), |
87 self._samples_data_source_factory.Create(request), | 84 self._samples_data_source_factory.Create(request), |
88 self._known_issues_data_source, | 85 self._known_issues_data_source, |
89 self._sidenav_data_source_factory.Create(path), | 86 self._sidenav_data_source_factory.Create(path), |
90 self._cache, | 87 self._cache, |
91 self._public_template_path, | 88 self._public_template_path, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 def get(self, key): | 150 def get(self, key): |
154 return self.GetTemplate(self._private_template_path, key) | 151 return self.GetTemplate(self._private_template_path, key) |
155 | 152 |
156 def GetTemplate(self, base_path, template_name): | 153 def GetTemplate(self, base_path, template_name): |
157 real_path = FormatKey(template_name) | 154 real_path = FormatKey(template_name) |
158 try: | 155 try: |
159 return self._cache.GetFromFile(base_path + '/' + real_path) | 156 return self._cache.GetFromFile(base_path + '/' + real_path) |
160 except FileNotFoundError as e: | 157 except FileNotFoundError as e: |
161 logging.info(e) | 158 logging.info(e) |
162 return None | 159 return None |
OLD | NEW |