Skip to content

Commit

Permalink
Make the template pluggable with z3c.template pattern
Browse files Browse the repository at this point in the history
Register default template for menu item
Reflect changes in tests
  • Loading branch information
projekt01 committed Feb 15, 2008
1 parent ad06a6a commit 2bdaefd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -60,6 +60,7 @@ def read(*rnames):
install_requires = [
'setuptools',
'z3c.i18n',
'z3c.template',
'zope.app.component',
'zope.app.pagetemplate',
'zope.schema',
Expand Down
19 changes: 14 additions & 5 deletions src/z3c/menu/ready2go/README.txt
Expand Up @@ -5,7 +5,20 @@ Ready 2 go Menu
The z3c.menu.ready2go package provides a menu implementation which allows you
to implement menus based on content providers and viewlets.

Let's see what this means.
First let's setup our defualt menu item template:

>>> import os
>>> import zope.component
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.publisher.interfaces.browser import IBrowserView
>>> from z3c.template.interfaces import IContentTemplate
>>> from z3c.template.template import TemplateFactory
>>> import z3c.menu.ready2go
>>> baseDir = os.path.split(z3c.menu.ready2go.__file__)[0]
>>> itemTemplate = os.path.join(baseDir, 'item.pt')
>>> itemTemplateFactory = TemplateFactory(itemTemplate, 'text/html')
>>> zope.component.provideAdapter(itemTemplateFactory,
... (IBrowserView, IDefaultBrowserLayer), IContentTemplate)


Global Menu
Expand Down Expand Up @@ -54,7 +67,6 @@ Our menu managers implement IMenuManager:
We also need our checker adapter which can check if a menu item is available
and/or selected:

>>> import zope.component
>>> from z3c.menu.ready2go import checker
>>> zope.component.provideAdapter(checker.GlobalSelectedChecker)
>>> zope.component.provideAdapter(checker.SiteSelectedChecker)
Expand Down Expand Up @@ -97,7 +109,6 @@ traaverse to the site within the publisher/traverser:

And we need a view which knows about it's parent:

>>> from zope.publisher.interfaces.browser import IBrowserView
>>> class View(contained.Contained):
...
... zope.interface.implements(IBrowserView)
Expand Down Expand Up @@ -139,8 +150,6 @@ Global Menu Item

Now we register a context menu item for our IGlobalMenu:

>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer

>>> from z3c.menu.ready2go.item import GlobalMenuItem
>>> class MyGlobalMenuItem(GlobalMenuItem):
...
Expand Down
13 changes: 13 additions & 0 deletions src/z3c/menu/ready2go/browser.zcml
@@ -0,0 +1,13 @@
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns="http://namespaces.zope.org/browser"
xmlns:z3c="http://namespaces.zope.org/z3c"
i18n_domain="z3c">

<z3c:template
template="item.pt"
for=".item.MenuItem"
layer="zope.publisher.interfaces.browser.IBrowserRequest"
/>

</configure>
2 changes: 2 additions & 0 deletions src/z3c/menu/ready2go/configure.zcml
Expand Up @@ -13,4 +13,6 @@
factory=".checker.ContextSelectedChecker"
/>

<include file="browser.zcml" />

</configure>
4 changes: 2 additions & 2 deletions src/z3c/menu/ready2go/item.py
Expand Up @@ -22,16 +22,16 @@

from zope.viewlet import viewlet
from zope.app.component import hooks
from zope.app.pagetemplate import ViewPageTemplateFile

from z3c.template.template import getPageTemplate
from z3c.menu.ready2go import interfaces


# base menu item mixin
class MenuItem(viewlet.ViewletBase):
"""Menu item base."""

template = ViewPageTemplateFile('item.pt')
template = getPageTemplate()

# internal approved values
approved = False
Expand Down
15 changes: 15 additions & 0 deletions src/z3c/menu/ready2go/zcml.txt
Expand Up @@ -5,6 +5,21 @@ Z3C Menu directives
Show how we can use the menu directive. Register the meta configuration for
the directive.

First let's setup our defualt menu item template first:

>>> import os
>>> import zope.component
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.publisher.interfaces.browser import IBrowserView
>>> from z3c.template.interfaces import IContentTemplate
>>> from z3c.template.template import TemplateFactory
>>> import z3c.menu.ready2go
>>> baseDir = os.path.split(z3c.menu.ready2go.__file__)[0]
>>> itemTemplate = os.path.join(baseDir, 'item.pt')
>>> itemTemplateFactory = TemplateFactory(itemTemplate, 'text/html')
>>> zope.component.provideAdapter(itemTemplateFactory,
... (IBrowserView, IDefaultBrowserLayer), IContentTemplate)

>>> import sys
>>> from zope.configuration import xmlconfig
>>> import z3c.menu.ready2go
Expand Down

0 comments on commit 2bdaefd

Please sign in to comment.