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

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

Issue 437323003: Docserver: Factor SamplesModel out of SamplesDataSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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
« no previous file with comments | « chrome/common/extensions/docs/server2/server_instance.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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 from data_source_registry import CreateDataSources 5 from data_source_registry import CreateDataSources
6 from third_party.handlebar import Handlebar 6 from third_party.handlebar import Handlebar
7 from url_constants import GITHUB_BASE, EXTENSIONS_SAMPLES 7 from url_constants import GITHUB_BASE, EXTENSIONS_SAMPLES
8 8
9 9
10 class TemplateRenderer(object): 10 class TemplateRenderer(object):
(...skipping 10 matching lines...) Expand all
21 additional_context=None): 21 additional_context=None):
22 '''Renders |template| using |request|. 22 '''Renders |template| using |request|.
23 23
24 Specify |data_sources| to only include the DataSources with the given names 24 Specify |data_sources| to only include the DataSources with the given names
25 when rendering the template. 25 when rendering the template.
26 26
27 Specify |additional_context| to inject additional template context when 27 Specify |additional_context| to inject additional template context when
28 rendering the template. 28 rendering the template.
29 ''' 29 '''
30 assert isinstance(template, Handlebar), type(template) 30 assert isinstance(template, Handlebar), type(template)
31 render_context = self._CreateDataSources(request) 31 render_context = CreateDataSources(self._server_instance, request)
32 if data_sources is not None: 32 if data_sources is not None:
33 render_context = dict((name, d) for name, d in render_context.iteritems() 33 render_context = dict((name, d) for name, d in render_context.iteritems()
34 if name in data_sources) 34 if name in data_sources)
35 render_context.update({ 35 render_context.update({
36 'apps_samples_url': GITHUB_BASE, 36 'apps_samples_url': GITHUB_BASE,
37 'base_path': self._server_instance.base_path, 37 'base_path': self._server_instance.base_path,
38 'extensions_samples_url': EXTENSIONS_SAMPLES, 38 'extensions_samples_url': EXTENSIONS_SAMPLES,
39 'static': self._server_instance.base_path + 'static', 39 'static': self._server_instance.base_path + 'static',
40 }) 40 })
41 if additional_context: 41 render_context.update(additional_context or {})
42 render_context.update(additional_context)
43 render_data = template.Render(render_context) 42 render_data = template.Render(render_context)
44 return render_data.text, render_data.errors 43 return render_data.text, render_data.errors
45
46 def _CreateDataSources(self, request):
47 server_instance = self._server_instance
48 data_sources = CreateDataSources(server_instance, request=request)
49 data_sources.update({
50 'samples': server_instance.samples_data_source_factory.Create(request),
51 })
52 return data_sources
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/server_instance.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698