Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/common/extensions/docs/server2/template_data_source.py

Issue 13896007: Devserver: run the cron over the examples. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try again to avoid .svn Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/docs/server2/subversion_file_system.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
7 from branch_utility import BranchUtility 8 from branch_utility import BranchUtility
8 from docs_server_utils import FormatKey 9 from docs_server_utils import FormatKey
9 import compiled_file_system as compiled_fs 10 import compiled_file_system as compiled_fs
10 from file_system import FileNotFoundError 11 from file_system import FileNotFoundError
11 from third_party.handlebar import Handlebar 12 from third_party.handlebar import Handlebar
12 import url_constants 13 import url_constants
13 14
14 # Increment this if the data model changes for TemplateDataSource. 15 # Increment this if the data model changes for TemplateDataSource.
15 _VERSION = 3 16 _VERSION = 3
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 self._private_template_path = private_template_path 108 self._private_template_path = private_template_path
108 self._static_resources = static_resources 109 self._static_resources = static_resources
109 110
110 def Render(self, template_name): 111 def Render(self, template_name):
111 """This method will render a template named |template_name|, fetching all 112 """This method will render a template named |template_name|, fetching all
112 the partial templates needed from |self._cache|. Partials are retrieved 113 the partial templates needed from |self._cache|. Partials are retrieved
113 from the TemplateDataSource with the |get| method. 114 from the TemplateDataSource with the |get| method.
114 """ 115 """
115 template = self.GetTemplate(self._public_template_path, template_name) 116 template = self.GetTemplate(self._public_template_path, template_name)
116 if not template: 117 if not template:
117 return '' 118 return None
118 # TODO error handling 119 # TODO error handling
119 render_data = template.render({ 120 render_data = template.render({
120 'api_list': self._api_list_data_source, 121 'api_list': self._api_list_data_source,
121 'apis': self._api_data_source, 122 'apis': self._api_data_source,
122 'branchInfo': self._branch_info, 123 'branchInfo': self._branch_info,
123 'intros': self._intro_data_source, 124 'intros': self._intro_data_source,
124 'sidenavs': self._sidenav_data_source, 125 'sidenavs': self._sidenav_data_source,
125 'partials': self, 126 'partials': self,
126 'samples': self._samples_data_source, 127 'samples': self._samples_data_source,
127 'static': self._static_resources, 128 'static': self._static_resources,
128 'app': 'app', 129 'app': 'app',
129 'extension': 'extension', 130 'extension': 'extension',
130 'apps_title': 'Apps', 131 'apps_title': 'Apps',
131 'extensions_title': 'Extensions', 132 'extensions_title': 'Extensions',
132 'apps_samples_url': url_constants.GITHUB_BASE, 133 'apps_samples_url': url_constants.GITHUB_BASE,
133 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES, 134 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES,
134 'true': True, 135 'true': True,
135 'false': False 136 'false': False
136 }) 137 })
137 if render_data.errors: 138 if render_data.errors:
138 logging.error('Handlebar error(s) rendering %s:\n%s' % 139 logging.error('Handlebar error(s) rendering %s:\n%s' %
139 (template_name, ' \n'.join(render_data.errors))) 140 (template_name, ' \n'.join(render_data.errors)))
140 return render_data.text 141 return render_data.text
141 142
142 def get(self, key): 143 def get(self, key):
143 return self.GetTemplate(self._private_template_path, key) 144 return self.GetTemplate(self._private_template_path, key)
144 145
145 def GetTemplate(self, base_path, template_name): 146 def GetTemplate(self, base_path, template_name):
146 real_path = FormatKey(template_name)
147 try: 147 try:
148 return self._cache.GetFromFile(base_path + '/' + real_path) 148 return self._cache.GetFromFile(
149 '/'.join((base_path, FormatKey(template_name))))
149 except FileNotFoundError as e: 150 except FileNotFoundError as e:
150 logging.warning('Template %s in %s not found: %s' % ( 151 logging.error(e)
151 template_name, base_path, e))
152 return None 152 return None
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/subversion_file_system.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698