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..1d4cc4281e0fe167ea3e14f40e6f4123cc3d6bca 100644 |
--- a/chrome/common/extensions/docs/server2/sidenav_data_source.py |
+++ b/chrome/common/extensions/docs/server2/sidenav_data_source.py |
@@ -21,24 +21,38 @@ def _AddLevels(items, level): |
if 'items' in item: |
_AddLevels(item['items'], level + 1) |
not at google - send to devlin
2013/12/18 05:10:14
need an extra \n here
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
- |
-def _AddSelected(items, path): |
- '''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'. |
+def _AddAnnotations(items, path, parent=None): |
+ '''Add 'selected', 'child_selected' and 'related' properties to |
+ |items| so that the sidenav can be expanded to show which menu item has |
+ been selected and the related pages section can be drawn. 'related' |
+ is added to all items with the same parent as the selected item. |
+ If more than one item exactly matches the path, the deepest one is considered |
+ 'selected'. A 'parent' property is added to the selected path. |
+ |
+ Returns True if an item was marked 'selected'. |
''' |
for item in items: |
- if item.get('href', '') == path: |
- item['selected'] = True |
- return True |
+ # depth first search |
not at google - send to devlin
2013/12/18 05:10:14
Comment is ok to leave out I think.
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
if 'items' in item: |
- if _AddSelected(item['items'], path): |
+ if _AddAnnotations(item['items'], path, item): |
item['child_selected'] = True |
return True |
+ if item.get('href', '') == path: |
+ item['selected'] = True |
+ if parent: |
+ item['parent'] = parent |
+ |
+ # navigate on siblings, marking them as related |
not at google - send to devlin
2013/12/18 05:10:14
the docstring on this function adequately covers t
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
+ for sibling in items: |
+ sibling['related'] = True |
+ |
+ return True |
+ |
return False |
+ |
not at google - send to devlin
2013/12/18 05:10:14
need 1 less \n here
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
class SidenavDataSource(DataSource): |
'''Provides templates with access to JSON files used to create the side |
navigation bar. |
@@ -78,13 +92,14 @@ class SidenavDataSource(DataSource): |
item['href'] = self._server_instance.base_path + href |
def Cron(self): |
- futures = [self._cache.GetFromFile('%s/%s_sidenav.json' % |
- (JSON_TEMPLATES, platform)) |
- for platform in ('apps', 'extensions')] |
- return Future(delegate=Gettable(lambda: [f.Get() for f in futures])) |
+ future = self._cache.GetFromFile('%s/chrome_sidenav.json' % |
+ (JSON_TEMPLATES)) |
+ return future |
not at google - send to devlin
2013/12/18 05:10:14
inline this (no need for the extra |future| variab
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
def get(self, key): |
not at google - send to devlin
2013/12/18 05:10:14
add:
# TODO(mangini/kalman): Use |key| to decide
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
- sidenav = copy.deepcopy(self._cache.GetFromFile( |
- '%s/%s_sidenav.json' % (JSON_TEMPLATES, key)).Get()) |
- _AddSelected(sidenav, self._server_instance.base_path + self._request.path) |
- return sidenav |
+ sidenav = self._cache.GetFromFile( |
+ '%s/chrome_sidenav.json' % JSON_TEMPLATES).Get() |
+ sidenav = copy.deepcopy(sidenav) |
+ _AddAnnotations(sidenav, |
+ self._server_instance.base_path + self._request.path) |
not at google - send to devlin
2013/12/18 05:10:14
indent -= 3 to align with the (
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|
+ return sidenav |
not at google - send to devlin
2013/12/18 05:10:14
no trailing space
Renato Mangini (chromium)
2013/12/18 13:25:30
Done.
|