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

Unified Diff: chrome/common/extensions/docs/server2/sidenav_data_source.py

Issue 12521030: Extension docs: Include sidenav in 404 pages (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/sidenav_data_source.py
===================================================================
--- chrome/common/extensions/docs/server2/sidenav_data_source.py (revision 202781)
+++ chrome/common/extensions/docs/server2/sidenav_data_source.py (working copy)
@@ -14,17 +14,21 @@
menu.
"""
class Factory(object):
- def __init__(self, compiled_fs_factory, json_path):
+ def __init__(self, compiled_fs_factory, json_path, base_path):
self._cache = compiled_fs_factory.Create(self._CreateSidenavDict,
SidenavDataSource)
self._json_path = json_path
+ self._base_path = base_path
def Create(self, path):
"""Create a SidenavDataSource, binding it to |path|. |path| is the url
of the page that is being rendered. It is used to determine which item
in the sidenav should be highlighted.
"""
- return SidenavDataSource(self._cache, self._json_path, path)
+ return SidenavDataSource(self._cache,
+ self._json_path,
+ path,
+ self._base_path)
def _AddLevels(self, items, level):
"""Levels represent how deeply this item is nested in the sidenav. We
@@ -40,14 +44,15 @@
self._AddLevels(items, 2);
return items
- def __init__(self, cache, json_path, path):
+ def __init__(self, cache, json_path, path, base_path):
self._cache = cache
self._json_path = json_path
- self._file_name = path.split('/')[-1]
+ self._file_name = path
+ self._file_dir = base_path
def _AddSelected(self, items):
for item in items:
- if item.get('fileName', '') == self._file_name:
+ if item.get('href', '') == self._file_name:
item['selected'] = True
return True
if 'items' in item:
@@ -56,8 +61,19 @@
return True
return False
+ def _ConvertToAbsolutePath(self, items):
+ for item in items:
+ file_name = item.get('href')
+ if file_name is not None and not file_name.startswith(('/',
not at google - send to devlin 2013/05/29 23:16:46 I think they should *all* start with a '/' and we
+ 'http://',
+ 'https://')):
+ item['href'] = '%s/%s' % (self._file_dir, file_name)
+ if 'items' in item:
+ self._ConvertToAbsolutePath(item['items'])
+
def get(self, key):
sidenav = copy.deepcopy(self._cache.GetFromFile(
'%s/%s_sidenav.json' % (self._json_path, key)))
self._AddSelected(sidenav)
+ self._ConvertToAbsolutePath(sidenav)
return sidenav

Powered by Google App Engine
This is Rietveld 408576698