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

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

Issue 10804036: Extensions Docs Server: Internationalized samples (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: SamplesDataSource.Factory Created 8 years, 5 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 from path_utils import FormatKey 5 from path_utils import FormatKey
6 from third_party.handlebar import Handlebar 6 from third_party.handlebar import Handlebar
7 7
8 EXTENSIONS_URL = '/chrome/extensions' 8 EXTENSIONS_URL = '/chrome/extensions'
9 9
10 def _MakeBranchDict(branch): 10 def _MakeBranchDict(branch):
(...skipping 21 matching lines...) Expand all
32 """ 32 """
33 33
34 class Factory(object): 34 class Factory(object):
35 """ A factory to create lightweight TemplateDataSource instances bound to 35 """ A factory to create lightweight TemplateDataSource instances bound to
36 individual Requests. 36 individual Requests.
37 """ 37 """
38 def __init__(self, 38 def __init__(self,
39 branch, 39 branch,
40 api_data_source, 40 api_data_source,
41 intro_data_source, 41 intro_data_source,
42 samples_data_source, 42 samples_data_source_factory,
43 cache_builder, 43 cache_builder,
44 base_paths): 44 base_paths):
45 self._branch_info = _MakeBranchDict(branch) 45 self._branch_info = _MakeBranchDict(branch)
46 self._static_resources = ((('/' + branch) if branch != 'local' else '') + 46 self._static_resources = ((('/' + branch) if branch != 'local' else '') +
47 '/static') 47 '/static')
48 self._api_data_source = api_data_source 48 self._api_data_source = api_data_source
49 self._intro_data_source = intro_data_source 49 self._intro_data_source = intro_data_source
50 self._samples_data_source = samples_data_source 50 self._samples_data_source_factory = samples_data_source_factory
51 self._cache = cache_builder.build(Handlebar) 51 self._cache = cache_builder.build(Handlebar)
52 self._base_paths = base_paths 52 self._base_paths = base_paths
53 53
54 def Create(self, request): 54 def Create(self, request):
55 """ Returns a new TemplateDataSource bound to |request|. 55 """ Returns a new TemplateDataSource bound to |request|.
56 """ 56 """
57 return TemplateDataSource(self._branch_info, 57 return TemplateDataSource(self._branch_info,
58 self._static_resources, 58 self._static_resources,
59 self._api_data_source, 59 self._api_data_source,
60 self._intro_data_source, 60 self._intro_data_source,
61 self._samples_data_source, 61 self._samples_data_source_factory,
62 self._cache, 62 self._cache,
63 self._base_paths, 63 self._base_paths,
64 request) 64 request)
65 65
66 def __init__(self, 66 def __init__(self,
67 branch_info, 67 branch_info,
68 static_resources, 68 static_resources,
69 api_data_source, 69 api_data_source,
70 intro_data_source, 70 intro_data_source,
71 samples_data_source, 71 samples_data_source_factory,
72 cache, 72 cache,
73 base_paths, 73 base_paths,
74 request): 74 request):
75 self._branch_info = branch_info 75 self._branch_info = branch_info
76 self._static_resources = static_resources 76 self._static_resources = static_resources
77 self._api_data_source = api_data_source 77 self._api_data_source = api_data_source
78 self._intro_data_source = intro_data_source 78 self._intro_data_source = intro_data_source
79 self._samples_data_source = samples_data_source 79 self._samples_data_source = samples_data_source_factory.Create(request)
80 self._cache = cache 80 self._cache = cache
81 self._base_paths = base_paths 81 self._base_paths = base_paths
82 self._request = request 82 self._request = request
83 83
84 def Render(self, template_name): 84 def Render(self, template_name):
85 """This method will render a template named |template_name|, fetching all 85 """This method will render a template named |template_name|, fetching all
86 the partial templates needed from |self._cache|. Partials are retrieved 86 the partial templates needed from |self._cache|. Partials are retrieved
87 from the TemplateDataSource with the |get| method. 87 from the TemplateDataSource with the |get| method.
88 """ 88 """
89 template = self.get(template_name) 89 template = self.get(template_name)
(...skipping 13 matching lines...) Expand all
103 return self.get(key) 103 return self.get(key)
104 104
105 def get(self, key): 105 def get(self, key):
106 real_path = FormatKey(key) 106 real_path = FormatKey(key)
107 for base_path in self._base_paths: 107 for base_path in self._base_paths:
108 try: 108 try:
109 return self._cache.GetFromFile(base_path + '/' + real_path) 109 return self._cache.GetFromFile(base_path + '/' + real_path)
110 except Exception: 110 except Exception:
111 pass 111 pass
112 return None 112 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698