Commits

Matthew Schinckel committed 12ddc3a

Resolves #3: fix missing import.
Support classes on the menu items.
Support button-style menu items.

  • Participants
  • Parent commits a0cabf0

Comments (0)

Files changed (5)

File menus/templates/menu/button-item.html

+<a href="{{ url }}" id="{{ element_id }}" class="btn {{ classes }}">
+  {% for icon in icons %}<i class="icon-{{ icon }}"></i>{% endfor %}
+  {{ text|safe }}
+</a>

File menus/templates/menu/item.html

-<a href="{{ url }}" id="{{ element_id }}" class="{{ classes }}">{{ text|safe }}</a>
+<a href="{{ url }}" id="{{ element_id }}" class="{{ classes }}">
+  {% if icon %}<i class="icon-{{ icon }}"></i>{% endif %}
+  {{ text|safe }}
+</a>

File menus/templates/menu/li-button-item.html

+<li class="{{ classes }}">{% include "menu/button-item.html" with classes="" %}</li>

File menus/templates/menu/li-item.html

-<li class="{{ classes }}">{% include "menu/item.html" %}</li>
+<li class="{{ classes }}">{% include "menu/item.html" with classes="" %}</li>

File menus/templatetags/menu_item.py

 
 from django import template
 from django.conf import settings
-from django.core.urlresolvers import Resolver404
+from django.core.urlresolvers import Resolver404, reverse, resolve
+from django.utils.itercompat import is_iterable
 
 register = template.Library()
-from django.core.urlresolvers import reverse, resolve
 
 def get_callable_cells(function):
     """
         self.template_file = template_file or 'menu/item.html'
         self.url = url
         self.text = text
-        self.classes = classes or ""
+        self.classes = classes if classes else ""
+        self.icons = []
+        if classes:
+            self.classes = classes
+            if 'icon:' in classes:
+                classes = classes.strip("\"'").split(' ')
+                for cl in list(classes):
+                    if cl.startswith('icon:'):
+                        self.icons.append(cl[5:])
+                        classes.remove(cl)
+                self.classes = '"' + " ".join(classes) +'"'
         self.nodelist = []
         
     def render(self, context):
         context.render_context[self] = {
             'url': url,
             'text': text,
-            'classes': classes
+            'classes': classes,
+            'icons': self.icons
         }
         
         local = dict(context.render_context[self])
     return inner
 
 register.tag('menu_item', base_menu_item())
-register.tag('li_menu_item', base_menu_item('menu/li-item.html'))
+register.tag('li_menu_item', base_menu_item('menu/li-item.html'))
+register.tag('button_menu_item', base_menu_item('menu/button-item.html'))
+register.tag('li_button_menu_item', base_menu_item('menu/li-button-item.html'))