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

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

Issue 12521030: Extension docs: Include sidenav in 404 pages (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: see last comment Created 7 years, 6 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 logging 5 import logging
6 import os 6 import os
7 7
8 from branch_utility import BranchUtility 8 from branch_utility import BranchUtility
9 import compiled_file_system as compiled_fs 9 import compiled_file_system as compiled_fs
10 from docs_server_utils import FormatKey 10 from docs_server_utils import FormatKey
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 channel_name, 44 channel_name,
45 api_data_source_factory, 45 api_data_source_factory,
46 api_list_data_source_factory, 46 api_list_data_source_factory,
47 intro_data_source_factory, 47 intro_data_source_factory,
48 samples_data_source_factory, 48 samples_data_source_factory,
49 sidenav_data_source_factory, 49 sidenav_data_source_factory,
50 compiled_fs_factory, 50 compiled_fs_factory,
51 ref_resolver_factory, 51 ref_resolver_factory,
52 public_template_path, 52 public_template_path,
53 private_template_path, 53 private_template_path,
54 static_path): 54 base_path):
55 self._branch_info = _MakeChannelDict(channel_name) 55 self._branch_info = _MakeChannelDict(channel_name)
56 self._api_data_source_factory = api_data_source_factory 56 self._api_data_source_factory = api_data_source_factory
57 self._api_list_data_source_factory = api_list_data_source_factory 57 self._api_list_data_source_factory = api_list_data_source_factory
58 self._intro_data_source_factory = intro_data_source_factory 58 self._intro_data_source_factory = intro_data_source_factory
59 self._samples_data_source_factory = samples_data_source_factory 59 self._samples_data_source_factory = samples_data_source_factory
60 self._sidenav_data_source_factory = sidenav_data_source_factory 60 self._sidenav_data_source_factory = sidenav_data_source_factory
61 self._cache = compiled_fs_factory.Create(self._CreateTemplate, 61 self._cache = compiled_fs_factory.Create(self._CreateTemplate,
62 TemplateDataSource) 62 TemplateDataSource)
63 self._ref_resolver = ref_resolver_factory.Create() 63 self._ref_resolver = ref_resolver_factory.Create()
64 self._public_template_path = public_template_path 64 self._public_template_path = public_template_path
65 self._private_template_path = private_template_path 65 self._private_template_path = private_template_path
66 self._static_resources = static_path 66 self._static_resources = '%s/static' % base_path
67 67
68 def _CreateTemplate(self, template_name, text): 68 def _CreateTemplate(self, template_name, text):
69 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) 69 return Handlebar(self._ref_resolver.ResolveAllLinks(text))
70 70
71 def Create(self, request, path): 71 def Create(self, request, path):
72 """Returns a new TemplateDataSource bound to |request|. 72 """Returns a new TemplateDataSource bound to |request|.
73 """ 73 """
74 return TemplateDataSource( 74 return TemplateDataSource(
75 self._branch_info, 75 self._branch_info,
76 self._api_data_source_factory.Create(request), 76 self._api_data_source_factory.Create(request),
77 self._api_list_data_source_factory.Create(), 77 self._api_list_data_source_factory.Create(),
78 self._intro_data_source_factory.Create(), 78 self._intro_data_source_factory.Create(),
79 self._samples_data_source_factory.Create(request), 79 self._samples_data_source_factory.Create(request),
80 self._sidenav_data_source_factory.Create(path), 80 self._sidenav_data_source_factory.Create(),
81 self._cache, 81 self._cache,
82 self._public_template_path, 82 self._public_template_path,
83 self._private_template_path, 83 self._private_template_path,
84 self._static_resources) 84 self._static_resources)
85 85
86 def __init__(self, 86 def __init__(self,
87 branch_info, 87 branch_info,
88 api_data_source, 88 api_data_source,
89 api_list_data_source, 89 api_list_data_source,
90 intro_data_source, 90 intro_data_source,
(...skipping 12 matching lines...) Expand all
103 self._cache = cache 103 self._cache = cache
104 self._public_template_path = public_template_path 104 self._public_template_path = public_template_path
105 self._private_template_path = private_template_path 105 self._private_template_path = private_template_path
106 self._static_resources = static_resources 106 self._static_resources = static_resources
107 107
108 def Render(self, template_name): 108 def Render(self, template_name):
109 """This method will render a template named |template_name|, fetching all 109 """This method will render a template named |template_name|, fetching all
110 the partial templates needed from |self._cache|. Partials are retrieved 110 the partial templates needed from |self._cache|. Partials are retrieved
111 from the TemplateDataSource with the |get| method. 111 from the TemplateDataSource with the |get| method.
112 """ 112 """
113 self._sidenav_data_source.SetPath(template_name)
not at google - send to devlin 2013/05/29 17:59:09 I don't understand. the name of the template being
113 template = self.GetTemplate(self._public_template_path, template_name) 114 template = self.GetTemplate(self._public_template_path, template_name)
114 if not template: 115 if not template:
115 return None 116 return None
116 # TODO error handling 117 # TODO error handling
117 render_data = template.render({ 118 render_data = template.render({
118 'api_list': self._api_list_data_source, 119 'api_list': self._api_list_data_source,
119 'apis': self._api_data_source, 120 'apis': self._api_data_source,
120 'branchInfo': self._branch_info, 121 'branchInfo': self._branch_info,
121 'intros': self._intro_data_source, 122 'intros': self._intro_data_source,
122 'sidenavs': self._sidenav_data_source, 123 'sidenavs': self._sidenav_data_source,
(...skipping 21 matching lines...) Expand all
144 145
145 def get(self, key): 146 def get(self, key):
146 return self.GetTemplate(self._private_template_path, key) 147 return self.GetTemplate(self._private_template_path, key)
147 148
148 def GetTemplate(self, base_path, template_name): 149 def GetTemplate(self, base_path, template_name):
149 try: 150 try:
150 return self._cache.GetFromFile( 151 return self._cache.GetFromFile(
151 '/'.join((base_path, FormatKey(template_name)))) 152 '/'.join((base_path, FormatKey(template_name))))
152 except FileNotFoundError as e: 153 except FileNotFoundError as e:
153 return None 154 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698