Skip to content

Commit 4d8d3be

Browse files
authored
Merge pull request #7 from lucaskuzma/master
checks if url is substring of path for root items
2 parents 4f2bd25 + 60d0299 commit 4d8d3be

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

menu_generator/menu.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,20 @@ def _get_url(self, item_dict):
8282

8383
def _is_selected(self, item_dict):
8484
"""
85-
Given a menu item dictionary, it returns true if `url` is on path.
85+
Given a menu item dictionary, it returns true if `url` is on path,
86+
unless the item is marked as a root, in which case returns true if `url` is part of path.
8687
"""
8788
url = self._get_url(item_dict)
88-
return url == self.path
89+
if self._is_root(item_dict):
90+
return url in self.path
91+
else:
92+
return url == self.path
93+
94+
def _is_root(self, item_dict):
95+
"""
96+
Given a menu item dictionary, it returns true if item is marked as a `root`.
97+
"""
98+
return item_dict.get('root', False)
8999

90100
def _process_breadcrums(self, menu_list):
91101
"""

0 commit comments

Comments
 (0)