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

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

Issue 102593005: Clean patch with DCC static content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bumped versions of cron and app, so running server won't update Created 7 years 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 copy 5 import copy
6 import logging 6 import logging
7 7
8 from compiled_file_system import SingleFile, Unicode 8 from compiled_file_system import SingleFile, Unicode
9 from data_source import DataSource 9 from data_source import DataSource
10 from extensions_paths import JSON_TEMPLATES 10 from extensions_paths import JSON_TEMPLATES
(...skipping 20 matching lines...) Expand all
31 if item.get('href', '') == path: 31 if item.get('href', '') == path:
32 item['selected'] = True 32 item['selected'] = True
33 return True 33 return True
34 if 'items' in item: 34 if 'items' in item:
35 if _AddSelected(item['items'], path): 35 if _AddSelected(item['items'], path):
36 item['child_selected'] = True 36 item['child_selected'] = True
37 return True 37 return True
38 38
39 return False 39 return False
40 40
41 def _ProcessRelated(items, path, parent=None):
42 '''Add 'selected' and 'child_selected' properties to |items| so that the
43 sidenav can be expanded to show which menu item has been selected. Returns
44 True if an item was marked 'selected'.
45 '''
46 for item in items:
47 # depth first search
48 if 'items' in item:
49 result = _ProcessRelated(item['items'], path, item)
50 if result:
51 return result
52
53 if item.get('href', '') == path:
54 related = []
55 for sibling in items:
56 if sibling == item:
57 sibling = copy.deepcopy(sibling)
58 sibling['active'] = True
59 related.append(sibling)
60 return (related, parent)
61
62 return None
63
64
41 65
42 class SidenavDataSource(DataSource): 66 class SidenavDataSource(DataSource):
43 '''Provides templates with access to JSON files used to create the side 67 '''Provides templates with access to JSON files used to create the side
44 navigation bar. 68 navigation bar.
45 ''' 69 '''
46 def __init__(self, server_instance, request): 70 def __init__(self, server_instance, request):
47 self._cache = server_instance.compiled_fs_factory.Create( 71 self._cache = server_instance.compiled_fs_factory.Create(
48 server_instance.host_file_system_provider.GetTrunk(), 72 server_instance.host_file_system_provider.GetTrunk(),
49 self._CreateSidenavDict, 73 self._CreateSidenavDict,
50 SidenavDataSource) 74 SidenavDataSource)
(...skipping 21 matching lines...) Expand all
72 href = item.get('href') 96 href = item.get('href')
73 if href is not None and not href.startswith(('http://', 'https://')): 97 if href is not None and not href.startswith(('http://', 'https://')):
74 if not href.startswith('/'): 98 if not href.startswith('/'):
75 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) 99 logging.warn('Paths in sidenav must be qualified. %s is not.' % href)
76 else: 100 else:
77 href = href.lstrip('/') 101 href = href.lstrip('/')
78 item['href'] = self._server_instance.base_path + href 102 item['href'] = self._server_instance.base_path + href
79 103
80 def Cron(self): 104 def Cron(self):
81 futures = [self._cache.GetFromFile('%s/%s_sidenav.json' % 105 futures = [self._cache.GetFromFile('%s/%s_sidenav.json' %
82 (JSON_TEMPLATES, platform)) 106 (JSON_TEMPLATES, nav_type))
83 for platform in ('apps', 'extensions')] 107 for nav_type in ('top', 'related')]
not at google - send to devlin 2013/12/13 23:05:12 this should be just 'chrome' not ('top', 'related'
Renato Mangini (chromium) 2013/12/17 20:32:33 Done.
84 return Future(delegate=Gettable(lambda: [f.Get() for f in futures])) 108 return Future(delegate=Gettable(lambda: [f.Get() for f in futures]))
85 109
86 def get(self, key): 110 def get(self, key):
87 sidenav = copy.deepcopy(self._cache.GetFromFile( 111 sidenav = self._cache.GetFromFile(
88 '%s/%s_sidenav.json' % (JSON_TEMPLATES, key)).Get()) 112 '%s/chrome_sidenav.json' % JSON_TEMPLATES).Get()
89 _AddSelected(sidenav, self._server_instance.base_path + self._request.path) 113 if key == 'related':
114 (items, parent) = _ProcessRelated(sidenav,
115 self._server_instance.base_path + self._request.path)
not at google - send to devlin 2013/12/14 02:41:05 Also: it looks like _ProcessRelated can return Non
Renato Mangini (chromium) 2013/12/17 20:32:33 Done.
116 return {'items': items, 'parent': parent}
117 else:
118 sidenav = copy.deepcopy(sidenav)
119 _AddSelected(sidenav, self._server_instance.base_path + self._request.path )
not at google - send to devlin 2013/12/13 23:03:47 The change I'd rather see to this file is that the
Renato Mangini (chromium) 2013/12/17 20:32:33 Done, although the template is more complicated an
120
90 return sidenav 121 return sidenav
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698