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

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

Issue 26538009: Docserver: make file_system a property of Create (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: niggles Created 7 years, 2 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
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 6
7 from docs_server_utils import FormatKey 7 from docs_server_utils import FormatKey
8 from file_system import FileNotFoundError 8 from file_system import FileNotFoundError
9 from third_party.handlebar import Handlebar 9 from third_party.handlebar import Handlebar
10 import url_constants 10 import url_constants
(...skipping 15 matching lines...) Expand all
26 class Factory(object): 26 class Factory(object):
27 '''A factory to create lightweight TemplateDataSource instances bound to 27 '''A factory to create lightweight TemplateDataSource instances bound to
28 individual Requests. 28 individual Requests.
29 ''' 29 '''
30 def __init__(self, 30 def __init__(self,
31 api_data_source_factory, 31 api_data_source_factory,
32 api_list_data_source_factory, 32 api_list_data_source_factory,
33 intro_data_source_factory, 33 intro_data_source_factory,
34 samples_data_source_factory, 34 samples_data_source_factory,
35 compiled_fs_factory, 35 compiled_fs_factory,
36 file_system,
36 ref_resolver_factory, 37 ref_resolver_factory,
37 public_template_path, 38 public_template_path,
38 private_template_path, 39 private_template_path,
39 base_path): 40 base_path):
40 self._api_data_source_factory = api_data_source_factory 41 self._api_data_source_factory = api_data_source_factory
41 self._api_list_data_source_factory = api_list_data_source_factory 42 self._api_list_data_source_factory = api_list_data_source_factory
42 self._intro_data_source_factory = intro_data_source_factory 43 self._intro_data_source_factory = intro_data_source_factory
43 self._samples_data_source_factory = samples_data_source_factory 44 self._samples_data_source_factory = samples_data_source_factory
44 self._cache = compiled_fs_factory.Create(self._CreateTemplate, 45 self._cache = compiled_fs_factory.Create(file_system,
46 self._CreateTemplate,
45 TemplateDataSource) 47 TemplateDataSource)
46 self._ref_resolver = ref_resolver_factory.Create() 48 self._ref_resolver = ref_resolver_factory.Create()
47 self._public_template_path = public_template_path 49 self._public_template_path = public_template_path
48 self._private_template_path = private_template_path 50 self._private_template_path = private_template_path
49 self._base_path = base_path 51 self._base_path = base_path
50 52
51 def _CreateTemplate(self, template_name, text): 53 def _CreateTemplate(self, template_name, text):
52 return Handlebar(self._ref_resolver.ResolveAllLinks(text)) 54 return Handlebar(self._ref_resolver.ResolveAllLinks(text))
53 55
54 def Create(self, request, data_sources): 56 def Create(self, request, data_sources):
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 121
120 def get(self, key): 122 def get(self, key):
121 return self.GetTemplate(self._private_template_path, key) 123 return self.GetTemplate(self._private_template_path, key)
122 124
123 def GetTemplate(self, base_path, template_name): 125 def GetTemplate(self, base_path, template_name):
124 try: 126 try:
125 return self._cache.GetFromFile( 127 return self._cache.GetFromFile(
126 '/'.join((base_path, FormatKey(template_name)))).Get() 128 '/'.join((base_path, FormatKey(template_name)))).Get()
127 except FileNotFoundError: 129 except FileNotFoundError:
128 return None 130 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698