Ignore:
Timestamp:
23 Mar 2010, 14:34:14 (15 years ago)
Author:
uli
Message:

Show, how plugins work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/README.txt

    r4920 r5072  
    9797===========
    9898
     99
     100WAeUP SIRP plugins
     101==================
     102
     103waeup.sirp provides an API to 'plugin' components. Things that should
     104be setup at creation time of a WAeUP SIRP application can indicate
     105that by providing a utility providing IWAeUPSIRPPlugin.
     106
     107The plugins are looked up by an created app, which then will call the
     108``setup()`` method of each plugin.
     109
     110   >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     111   >>> from zope.component import getAdapters, getUtilitiesFor
     112   >>> sorted(list(getUtilitiesFor(IWAeUPSIRPPluggable)))
     113   [(u'accesscodes', <waeup.sirp.accesscodes...AccessCodePlugin ...)]
     114
     115
     116We can provide a new plugin like this:
     117
     118   >>> import grok
     119   >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     120   >>> class MyPlugin(grok.GlobalUtility):
     121   ...   grok.implements(IWAeUPSIRPPluggable)
     122   ...   def setup(self, site, name, logger):
     123   ...     print "Setup was called for"
     124   ...     print site
     125   ...   def update(self, site, name, logger):
     126   ...     pass
     127
     128When we register the plugin
     129
     130   >>> grok.testing.grok_component('MyPlugin', MyPlugin)
     131   True
     132
     133and setup a new WAeUP SIRP instance, we will get a message:
     134
     135   >>> from waeup.sirp.app import University
     136   >>> site = University()
     137   Setup was called for
     138   <waeup.sirp.app.University object at 0x...>
     139
     140Apparently the plugin can do with the University object whatever it
     141likes. That's what plugins are for.
Note: See TracChangeset for help on using the changeset viewer.