2
2
from __future__ import unicode_literals
3
3
from django import template
4
4
from menus .menu_pool import menu_pool
5
- from classytags .arguments import IntegerArgument , StringArgument , Argument
5
+ from classytags .arguments import IntegerArgument , StringArgument , Argument , Flag
6
6
from classytags .helpers import InclusionTag
7
7
from classytags .core import Options
8
8
from menus .templatetags .menu_tags import flatten , remove
@@ -56,9 +56,10 @@ class MainMenu(InclusionTag):
56
56
StringArgument ('template' , default = 'bootstrap/menu/navbar.html' , required = False ),
57
57
StringArgument ('namespace' , default = None , required = False ),
58
58
StringArgument ('root_id' , default = None , required = False ),
59
+ Flag ('embody_root' , default = False , true_values = ['embody_root' ]),
59
60
)
60
61
61
- def get_context (self , context , template , namespace , root_id ):
62
+ def get_context (self , context , template , namespace , root_id , embody_root ):
62
63
try :
63
64
# If there's an exception (500), default context_processors may not be called.
64
65
request = context ['request' ]
@@ -77,6 +78,9 @@ def get_context(self, context, template, namespace, root_id):
77
78
remove_parent .parent = None
78
79
start_level = node .level + 1
79
80
nodes = flatten (nodes )
81
+ if embody_root :
82
+ node .level = start_level
83
+ nodes .insert (0 , node )
80
84
else :
81
85
nodes = []
82
86
children = cut_levels (nodes , start_level )
@@ -93,11 +97,24 @@ class MainMenuBelowId(MainMenu):
93
97
Argument ('root_id' , default = None , required = False ),
94
98
StringArgument ('template' , default = 'bootstrap/menu/navbar.html' , required = False ),
95
99
StringArgument ('namespace' , default = None , required = False ),
100
+ Flag ('embody_root' , default = False , true_values = ['embody_root' ]),
96
101
)
97
102
98
103
register .tag (MainMenuBelowId )
99
104
100
105
106
+ class MainMenuEmbodyId (MainMenu ):
107
+ name = 'main_menu_embody_id'
108
+ options = Options (
109
+ Argument ('root_id' , default = None , required = False ),
110
+ StringArgument ('template' , default = 'bootstrap/menu/navbar.html' , required = False ),
111
+ StringArgument ('namespace' , default = None , required = False ),
112
+ Flag ('embody_root' , default = True , false_values = ['skip_root' ]),
113
+ )
114
+
115
+ register .tag (MainMenuEmbodyId )
116
+
117
+
101
118
class Paginator (InclusionTag ):
102
119
name = 'paginator'
103
120
template = 'bootstrap/components/paginator.html'
0 commit comments