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

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

Issue 10750017: Extensions Docs Server: Intro data source (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 third_party.handlebar import Handlebar 5 from third_party.handlebar import Handlebar
6 6
7 EXTENSIONS_URL = '/chrome/extensions' 7 EXTENSIONS_URL = '/chrome/extensions'
8 8
9 class TemplateDataSource(object): 9 class TemplateDataSource(object):
10 """This class fetches and compiles templates using the fetcher passed in with 10 """This class fetches and compiles templates using the fetcher passed in with
11 |cache_builder|. 11 |cache_builder|.
12 """ 12 """
13 def __init__(self, branch, api_data_source, cache_builder, base_paths): 13 def __init__(self,
14 branch,
15 api_data_source,
16 intro_data_source,
17 cache_builder,
18 base_paths):
14 self._branch_info = self._MakeBranchDict(branch) 19 self._branch_info = self._MakeBranchDict(branch)
15 self._static_resources = ((('/' + branch) if branch != 'local' else '') + 20 self._static_resources = ((('/' + branch) if branch != 'local' else '') +
16 '/static') 21 '/static')
17 self._api_data_source = api_data_source 22 self._api_data_source = api_data_source
23 self._intro_data_source = intro_data_source
18 self._cache = cache_builder.build(self._LoadTemplate) 24 self._cache = cache_builder.build(self._LoadTemplate)
19 self._base_paths = base_paths 25 self._base_paths = base_paths
20 26
21 def _MakeBranchDict(self, branch): 27 def _MakeBranchDict(self, branch):
22 return { 28 return {
23 'showWarning': branch != 'stable', 29 'showWarning': branch != 'stable',
24 'branches': [ 30 'branches': [
25 { 'name': 'Stable', 'path': EXTENSIONS_URL + '/stable' }, 31 { 'name': 'Stable', 'path': EXTENSIONS_URL + '/stable' },
26 { 'name': 'Dev', 'path': EXTENSIONS_URL + '/dev' }, 32 { 'name': 'Dev', 'path': EXTENSIONS_URL + '/dev' },
27 { 'name': 'Beta', 'path': EXTENSIONS_URL + '/beta' }, 33 { 'name': 'Beta', 'path': EXTENSIONS_URL + '/beta' },
(...skipping 10 matching lines...) Expand all
38 the partial templates needed from |self._cache|. Partials are retrieved 44 the partial templates needed from |self._cache|. Partials are retrieved
39 from the TemplateDataSource with the |get| method. 45 from the TemplateDataSource with the |get| method.
40 """ 46 """
41 template = self.get(template_name) 47 template = self.get(template_name)
42 if not template: 48 if not template:
43 return '' 49 return ''
44 # TODO error handling 50 # TODO error handling
45 return template.render({ 51 return template.render({
46 'apis': self._api_data_source, 52 'apis': self._api_data_source,
47 'branchInfo': self._branch_info, 53 'branchInfo': self._branch_info,
54 'intros': self._intro_data_source,
48 'partials': self, 55 'partials': self,
49 'static': self._static_resources 56 'static': self._static_resources
50 }).text 57 }).text
51 58
52 def __getitem__(self, key): 59 def __getitem__(self, key):
53 return self.get(key) 60 return self.get(key)
54 61
55 def get(self, key): 62 def get(self, key):
56 index = key.rfind('.html') 63 index = key.rfind('.html')
57 if index > 0: 64 if index > 0:
58 key = key[:index] 65 key = key[:index]
59 safe_key = key.replace('.', '_') 66 safe_key = key.replace('.', '_')
60 real_path = safe_key + '.html' 67 real_path = safe_key + '.html'
61 for base_path in self._base_paths: 68 for base_path in self._base_paths:
62 try: 69 try:
63 return self._cache.get(base_path + '/' + real_path) 70 return self._cache.get(base_path + '/' + real_path)
64 except: 71 except:
65 pass 72 pass
66 return None 73 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698