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

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

Issue 14273041: Doc server manifest page generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manifest Update preview 2 Created 7 years, 7 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
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 json
5 import logging 6 import logging
6 import os 7 import os
7 import traceback 8 import traceback
8 9
9 from branch_utility import BranchUtility 10 from branch_utility import BranchUtility
10 import compiled_file_system as compiled_fs 11 import compiled_file_system as compiled_fs
11 from docs_server_utils import FormatKey 12 from docs_server_utils import FormatKey
12 from file_system import FileNotFoundError 13 from file_system import FileNotFoundError
14 from manifest_data_source import ManifestDataSource
15 from svn_constants import JSON_PATH
13 from third_party.handlebar import Handlebar 16 from third_party.handlebar import Handlebar
14 import url_constants 17 import url_constants
15 18
16 EXTENSIONS_URL = '/chrome/extensions' 19 EXTENSIONS_URL = '/chrome/extensions'
17 20
18 def _MakeChannelDict(channel_name): 21 def _MakeChannelDict(channel_name):
19 channel_dict = { 22 channel_dict = {
20 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()], 23 'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()],
21 'current': channel_name 24 'current': channel_name
22 } 25 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 self._api_list_data_source_factory = api_list_data_source_factory 60 self._api_list_data_source_factory = api_list_data_source_factory
58 self._intro_data_source_factory = intro_data_source_factory 61 self._intro_data_source_factory = intro_data_source_factory
59 self._samples_data_source_factory = samples_data_source_factory 62 self._samples_data_source_factory = samples_data_source_factory
60 self._sidenav_data_source_factory = sidenav_data_source_factory 63 self._sidenav_data_source_factory = sidenav_data_source_factory
61 self._cache = compiled_fs_factory.Create(self._CreateTemplate, 64 self._cache = compiled_fs_factory.Create(self._CreateTemplate,
62 TemplateDataSource) 65 TemplateDataSource)
63 self._ref_resolver = ref_resolver_factory.Create() 66 self._ref_resolver = ref_resolver_factory.Create()
64 self._public_template_path = public_template_path 67 self._public_template_path = public_template_path
65 self._private_template_path = private_template_path 68 self._private_template_path = private_template_path
66 self._static_resources = '/%s/static' % channel_name 69 self._static_resources = '/%s/static' % channel_name
70 self._manifest_source = ManifestDataSource(
71 compiled_fs_factory, TemplateDataSource)
not at google - send to devlin 2013/05/03 15:56:25 pass this in from ServerInstance like the other de
67 72
68 def _CreateTemplate(self, template_name, text): 73 def _CreateTemplate(self, template_name, text):
69 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) 74 return Handlebar(self._ref_resolver.ResolveAllLinks(text))
70 75
71 def Create(self, request, path): 76 def Create(self, request, path):
72 """Returns a new TemplateDataSource bound to |request|. 77 """Returns a new TemplateDataSource bound to |request|.
73 """ 78 """
74 return TemplateDataSource( 79 return TemplateDataSource(
75 self._branch_info, 80 self._branch_info,
76 self._api_data_source_factory.Create(request), 81 self._api_data_source_factory.Create(request),
77 self._api_list_data_source_factory.Create(), 82 self._api_list_data_source_factory.Create(),
78 self._intro_data_source_factory.Create(), 83 self._intro_data_source_factory.Create(),
79 self._samples_data_source_factory.Create(request), 84 self._samples_data_source_factory.Create(request),
80 self._sidenav_data_source_factory.Create(path), 85 self._sidenav_data_source_factory.Create(path),
86 self._manifest_source,
81 self._cache, 87 self._cache,
82 self._public_template_path, 88 self._public_template_path,
83 self._private_template_path, 89 self._private_template_path,
84 self._static_resources) 90 self._static_resources)
85 91
86 def __init__(self, 92 def __init__(self,
87 branch_info, 93 branch_info,
88 api_data_source, 94 api_data_source,
89 api_list_data_source, 95 api_list_data_source,
90 intro_data_source, 96 intro_data_source,
91 samples_data_source, 97 samples_data_source,
92 sidenav_data_source, 98 sidenav_data_source,
99 manifest_source,
93 cache, 100 cache,
94 public_template_path, 101 public_template_path,
95 private_template_path, 102 private_template_path,
96 static_resources): 103 static_resources):
97 self._branch_info = branch_info 104 self._branch_info = branch_info
98 self._api_list_data_source = api_list_data_source 105 self._api_list_data_source = api_list_data_source
99 self._intro_data_source = intro_data_source 106 self._intro_data_source = intro_data_source
100 self._samples_data_source = samples_data_source 107 self._samples_data_source = samples_data_source
101 self._api_data_source = api_data_source 108 self._api_data_source = api_data_source
102 self._sidenav_data_source = sidenav_data_source 109 self._sidenav_data_source = sidenav_data_source
103 self._cache = cache 110 self._cache = cache
104 self._public_template_path = public_template_path 111 self._public_template_path = public_template_path
105 self._private_template_path = private_template_path 112 self._private_template_path = private_template_path
106 self._static_resources = static_resources 113 self._static_resources = static_resources
114 self._manifest_source = manifest_source
107 115
108 def Render(self, template_name): 116 def Render(self, template_name):
109 """This method will render a template named |template_name|, fetching all 117 """This method will render a template named |template_name|, fetching all
110 the partial templates needed from |self._cache|. Partials are retrieved 118 the partial templates needed from |self._cache|. Partials are retrieved
111 from the TemplateDataSource with the |get| method. 119 from the TemplateDataSource with the |get| method.
112 """ 120 """
113 template = self.GetTemplate(self._public_template_path, template_name) 121 template = self.GetTemplate(self._public_template_path, template_name)
114 if not template: 122 if not template:
115 return None 123 return None
116 # TODO error handling 124 # TODO error handling
117 render_data = template.render({ 125 render_data = template.render({
118 'api_list': self._api_list_data_source, 126 'api_list': self._api_list_data_source,
119 'apis': self._api_data_source, 127 'apis': self._api_data_source,
120 'branchInfo': self._branch_info, 128 'branchInfo': self._branch_info,
121 'intros': self._intro_data_source, 129 'intros': self._intro_data_source,
122 'sidenavs': self._sidenav_data_source, 130 'sidenavs': self._sidenav_data_source,
123 'partials': self, 131 'partials': self,
132 'manifest_source': self._manifest_source,
124 'samples': self._samples_data_source, 133 'samples': self._samples_data_source,
125 'static': self._static_resources, 134 'static': self._static_resources,
126 'app': 'app', 135 'app': 'app',
127 'extension': 'extension', 136 'extension': 'extension',
128 'apps_title': 'Apps', 137 'apps_title': 'Apps',
129 'extensions_title': 'Extensions', 138 'extensions_title': 'Extensions',
130 'apps_samples_url': url_constants.GITHUB_BASE, 139 'apps_samples_url': url_constants.GITHUB_BASE,
131 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES, 140 'extensions_samples_url': url_constants.EXTENSIONS_SAMPLES,
132 'true': True, 141 'true': True,
133 'false': False 142 'false': False
134 }) 143 })
135 if render_data.errors: 144 if render_data.errors:
136 logging.error('Handlebar error(s) rendering %s:\n%s' % 145 logging.error('Handlebar error(s) rendering %s:\n%s' %
137 (template_name, ' \n'.join(render_data.errors))) 146 (template_name, ' \n'.join(render_data.errors)))
138 return render_data.text 147 return render_data.text
139 148
140 def get(self, key): 149 def get(self, key):
141 return self.GetTemplate(self._private_template_path, key) 150 return self.GetTemplate(self._private_template_path, key)
142 151
143 def GetTemplate(self, base_path, template_name): 152 def GetTemplate(self, base_path, template_name):
144 try: 153 try:
145 return self._cache.GetFromFile( 154 return self._cache.GetFromFile(
146 '/'.join((base_path, FormatKey(template_name)))) 155 '/'.join((base_path, FormatKey(template_name))))
147 except FileNotFoundError as e: 156 except FileNotFoundError as e:
148 logging.warning(traceback.format_exc()) 157 logging.warning(traceback.format_exc())
149 return None 158 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698