[Zope3-Users] z3c.menu

Christian Lück christian.lueck at ruhr-uni-bochum.de
Wed Sep 17 01:26:58 EDT 2008


Hi,

1)
in z3c.menu.simple.menu.GlobalMenuItem and ContextMenuItem the
urlEndings attribute seems not to work properly.
It is ether set by the superclass (zope.viewlet.viewlet.ViewletBase)
which sets arbitrary attributes passed in via zcml, or it is defaulted
to []. In the selected() method there is an iterator:

for urlEnding in self.urlEndings:
	...

But this way the unicode characters in the unicode string are iterated
over (or the default []). It would be better to split the urlEndings by
whitespaces and iterate over the resulting list.
Here is the diff. With it applied the package works fine for me.

---
/home/clueck/.buildout-eggs/z3c.menu-0.2.0-py2.5.egg/z3c/menu/simple/menu.py
2008-08-23 06:28:52.000000000 +0100
+++ menu.py	2008-09-17 05:37:59.000000000 +0100
@@ -83,13 +83,13 @@
 class ContextMenuItem(SimpleMenuItem):
     """Menu item viewlet generating context related links."""

-    urlEndings = []
+    urlEndings = u''
     viewURL = u''

     @property
     def selected(self):
         requestURL = self.request.getURL()
-        for urlEnding in self.urlEndings:
+        for urlEnding in self.urlEndings.split():
             if requestURL.endswith(urlEnding):
                 return True
         return False
@@ -103,13 +103,13 @@
 class GlobalMenuItem(SimpleMenuItem):
     """Menu item viewlet generating global/site related links."""

-    urlEndings = []
+    urlEndings = u''
     viewURL = u''

     @property
     def selected(self):
         requestURL = self.request.getURL()
-        for urlEnding in self.urlEndings:
+        for urlEnding in self.urlEndings.split():
             if requestURL.endswith(urlEnding):
                 return True
         return False



Or am I making a mistake in zcml? (Combination of interfaces in
multi-adapters are configured in that way, too.)

<browser:viewlet
	...
	urlEndings="viewX.html vievY.html viewZ.html"
	...
	/>


2) There is still another thing about z3c.menu--but it's yust a proposal.
z3c.menu sets the css class of the rendered menu item html snippet to
active-menu-item or inactive-menu-item. The package would be much more
powerfull, if one could decorate the rendered html-snippets with further
css classes,
e.g. <a class="inactive-menu-item sub-menu-item" ...>...</a>
One could configure it this way:

  <viewlet
      name="Contents"
      cssClass="sub-menu-item"
      viewURL="@@contents.html"
	...
      class="z3c.menu.simple.menu.ContextMenuItem"
	...
      />

The value of the class attribute is of type cdata-LIST according to the
TRs, at least since HTML 4.01.

Here is the diff for 1) and 2):

---
/home/clueck/.buildout-eggs/z3c.menu-0.2.0-py2.5.egg/z3c/menu/simple/menu.py
2008-08-23 06:28:52.000000000 +0100
+++ menu.py	2008-09-17 05:47:39.000000000 +0100
@@ -45,6 +45,7 @@
     selectedViewNames = None
     activeCSS = u'active-menu-item'
     inActiveCSS = u'inactive-menu-item'
+    cssClass = u''

     @property
     def title(self):
@@ -70,10 +71,14 @@

     @property
     def css(self):
+        if self.cssClass:
+            klass = u' ' + self.cssClass
+        else:
+            klass = u''
         if self.selected:
-            return self.activeCSS
+            return self.activeCSS + klass
         else:
-            return self.inActiveCSS
+            return self.inActiveCSS + klass

     def render(self):
         """Return the template with the option 'menus'"""
@@ -83,13 +88,13 @@
 class ContextMenuItem(SimpleMenuItem):
     """Menu item viewlet generating context related links."""

-    urlEndings = []
+    urlEndings = u''
     viewURL = u''

     @property
     def selected(self):
         requestURL = self.request.getURL()
-        for urlEnding in self.urlEndings:
+        for urlEnding in self.urlEndings.split():
             if requestURL.endswith(urlEnding):
                 return True
         return False
@@ -103,13 +108,13 @@
 class GlobalMenuItem(SimpleMenuItem):
     """Menu item viewlet generating global/site related links."""

-    urlEndings = []
+    urlEndings = u''
     viewURL = u''

     @property
     def selected(self):
         requestURL = self.request.getURL()
-        for urlEnding in self.urlEndings:
+        for urlEnding in self.urlEndings.split():
             if requestURL.endswith(urlEnding):
                 return True
         return False


Regards,
Christian


More information about the Zope3-users mailing list