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 | 9 |
10 EXTENSIONS_URL = '/chrome/extensions' | 10 EXTENSIONS_URL = '/chrome/extensions' |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 self._api_list_data_source = api_list_data_source | 53 self._api_list_data_source = api_list_data_source |
54 self._intro_data_source = intro_data_source | 54 self._intro_data_source = intro_data_source |
55 self._samples_data_source_factory = samples_data_source_factory | 55 self._samples_data_source_factory = samples_data_source_factory |
56 self._cache = cache_builder.build(Handlebar) | 56 self._cache = cache_builder.build(Handlebar) |
57 self._public_template_path = public_template_path | 57 self._public_template_path = public_template_path |
58 self._private_template_path = private_template_path | 58 self._private_template_path = private_template_path |
59 | 59 |
60 def Create(self, request): | 60 def Create(self, request): |
61 """Returns a new TemplateDataSource bound to |request|. | 61 """Returns a new TemplateDataSource bound to |request|. |
62 """ | 62 """ |
63 return TemplateDataSource(self._branch_info, | 63 return TemplateDataSource( |
64 self._static_resources, | 64 self._branch_info, |
65 self._api_data_source_factory, | 65 self._static_resources, |
66 self._api_list_data_source, | 66 self._api_data_source_factory.Create(request), |
67 self._intro_data_source, | 67 self._api_list_data_source, |
68 self._samples_data_source_factory, | 68 self._intro_data_source, |
69 self._cache, | 69 self._samples_data_source_factory.Create(request), |
70 self._public_template_path, | 70 self._cache, |
71 self._private_template_path, | 71 self._public_template_path, |
72 request) | 72 self._private_template_path, |
| 73 request) |
73 | 74 |
74 def __init__(self, | 75 def __init__(self, |
75 branch_info, | 76 branch_info, |
76 static_resources, | 77 static_resources, |
77 api_data_source_factory, | 78 api_data_source, |
78 api_list_data_source, | 79 api_list_data_source, |
79 intro_data_source, | 80 intro_data_source, |
80 samples_data_source_factory, | 81 samples_data_source, |
81 cache, | 82 cache, |
82 public_template_path, | 83 public_template_path, |
83 private_template_path, | 84 private_template_path, |
84 request): | 85 request): |
85 self._branch_info = branch_info | 86 self._branch_info = branch_info |
86 self._static_resources = static_resources | 87 self._static_resources = static_resources |
87 self._api_list_data_source = api_list_data_source | 88 self._api_list_data_source = api_list_data_source |
88 self._intro_data_source = intro_data_source | 89 self._intro_data_source = intro_data_source |
89 self._samples_data_source = samples_data_source_factory.Create(request) | 90 self._samples_data_source = samples_data_source |
90 self._api_data_source = api_data_source_factory.Create( | 91 self._api_data_source = api_data_source |
91 self._samples_data_source.values()) | |
92 self._cache = cache | 92 self._cache = cache |
93 self._public_template_path = public_template_path | 93 self._public_template_path = public_template_path |
94 self._private_template_path = private_template_path | 94 self._private_template_path = private_template_path |
95 self._request = request | 95 self._request = request |
96 | 96 |
97 def Render(self, template_name): | 97 def Render(self, template_name): |
98 """This method will render a template named |template_name|, fetching all | 98 """This method will render a template named |template_name|, fetching all |
99 the partial templates needed from |self._cache|. Partials are retrieved | 99 the partial templates needed from |self._cache|. Partials are retrieved |
100 from the TemplateDataSource with the |get| method. | 100 from the TemplateDataSource with the |get| method. |
101 """ | 101 """ |
(...skipping 17 matching lines...) Expand all Loading... |
119 def get(self, key): | 119 def get(self, key): |
120 return self.GetTemplate(self._private_template_path, key) | 120 return self.GetTemplate(self._private_template_path, key) |
121 | 121 |
122 def GetTemplate(self, base_path, template_name): | 122 def GetTemplate(self, base_path, template_name): |
123 real_path = FormatKey(template_name) | 123 real_path = FormatKey(template_name) |
124 try: | 124 try: |
125 return self._cache.GetFromFile(base_path + '/' + real_path) | 125 return self._cache.GetFromFile(base_path + '/' + real_path) |
126 except Exception as e: | 126 except Exception as e: |
127 logging.error(e) | 127 logging.error(e) |
128 return None | 128 return None |
OLD | NEW |