Index: chrome/common/extensions/docs/server2/sidenav_data_source.py |
diff --git a/chrome/common/extensions/docs/server2/sidenav_data_source.py b/chrome/common/extensions/docs/server2/sidenav_data_source.py |
index 598122a8ff39313dc66f1fb7d2aacb272e032d55..6b459f53e92eb6852ca8e41158477f980f83e5e1 100644 |
--- a/chrome/common/extensions/docs/server2/sidenav_data_source.py |
+++ b/chrome/common/extensions/docs/server2/sidenav_data_source.py |
@@ -38,6 +38,30 @@ def _AddSelected(items, path): |
return False |
+def _ProcessRelated(items, path, parent=None): |
+ '''Add 'selected' and 'child_selected' properties to |items| so that the |
+ sidenav can be expanded to show which menu item has been selected. Returns |
+ True if an item was marked 'selected'. |
+ ''' |
+ for item in items: |
+ # depth first search |
+ if 'items' in item: |
+ result = _ProcessRelated(item['items'], path, item) |
+ if result: |
+ return result |
+ |
+ if item.get('href', '') == path: |
+ related = [] |
+ for sibling in items: |
+ if sibling == item: |
+ sibling = copy.deepcopy(sibling) |
+ sibling['active'] = True |
+ related.append(sibling) |
+ return (related, parent) |
+ |
+ return None |
+ |
+ |
class SidenavDataSource(DataSource): |
'''Provides templates with access to JSON files used to create the side |
@@ -79,12 +103,19 @@ class SidenavDataSource(DataSource): |
def Cron(self): |
futures = [self._cache.GetFromFile('%s/%s_sidenav.json' % |
- (JSON_TEMPLATES, platform)) |
- for platform in ('apps', 'extensions')] |
+ (JSON_TEMPLATES, nav_type)) |
+ 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.
|
return Future(delegate=Gettable(lambda: [f.Get() for f in futures])) |
def get(self, key): |
- sidenav = copy.deepcopy(self._cache.GetFromFile( |
- '%s/%s_sidenav.json' % (JSON_TEMPLATES, key)).Get()) |
- _AddSelected(sidenav, self._server_instance.base_path + self._request.path) |
+ sidenav = self._cache.GetFromFile( |
+ '%s/chrome_sidenav.json' % JSON_TEMPLATES).Get() |
+ if key == 'related': |
+ (items, parent) = _ProcessRelated(sidenav, |
+ 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.
|
+ return {'items': items, 'parent': parent} |
+ else: |
+ sidenav = copy.deepcopy(sidenav) |
+ _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
|
+ |
return sidenav |