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

Unified 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: Fixed tests for sidenav_data_source 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 side-by-side diff with in-line comments
Download patch
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..cc43d52b93d4a6bfc54dcdbee92bf3cefbec2f4a 100644
--- a/chrome/common/extensions/docs/server2/sidenav_data_source.py
+++ b/chrome/common/extensions/docs/server2/sidenav_data_source.py
@@ -22,20 +22,33 @@ def _AddLevels(items, level):
_AddLevels(item['items'], level + 1)
-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
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'] = { 'title': parent.get('title', None),
+ 'href': parent.get('href', None) }
+
+ for sibling in items:
+ sibling['related'] = True
+
+ return True
+
return False
@@ -78,13 +91,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]))
+ return self._cache.GetFromFile('%s/chrome_sidenav.json' % (JSON_TEMPLATES))
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)
+ # TODO(mangini/kalman): Use |key| to decide which sidenav to use,
+ # which will require a more complex Cron method.
+ 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)
return sidenav
« no previous file with comments | « chrome/common/extensions/docs/server2/cron.yaml ('k') | chrome/common/extensions/docs/server2/sidenav_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698