[Checkins] SVN: grok/branches/neanderthal-reference-documentation/doc/reference/decorators.rst added missing decorators and examples

Luciano Ramalho luciano at ramalho.org
Tue Oct 2 10:54:19 EDT 2007


Log message for revision 80500:
  added missing decorators and examples
  

Changed:
  U   grok/branches/neanderthal-reference-documentation/doc/reference/decorators.rst

-=-
Modified: grok/branches/neanderthal-reference-documentation/doc/reference/decorators.rst
===================================================================
--- grok/branches/neanderthal-reference-documentation/doc/reference/decorators.rst	2007-10-02 14:54:17 UTC (rev 80499)
+++ grok/branches/neanderthal-reference-documentation/doc/reference/decorators.rst	2007-10-02 14:54:19 UTC (rev 80500)
@@ -13,16 +13,63 @@
 
 .. function:: subscribe(*classes_or_interfaces)
 
-   Declare that the decorated function subscribes to an event or a combination of
-   objects and events and register it.
+Declare that the decorated function subscribes to an event or a combination of
+objects and events and register it.
 
-   Applicable on module-level for functions. Requires at least one class or
-   interface as argument.
+Applicable on module-level for functions. Requires at least one class or
+interface as argument.
 
-   (Similar to Zope 3's :func:`subscriber` decorator, but automatically performs
-   the registration of the component.)
+(Similar to Zope 3's :func:`subscriber` decorator, but automatically performs
+the registration of the component.)
 
 
-grok.action
-===========
+:func:`grok.action` -- Declare a form submit handler
+=====================================================
 
+
+:func:`grok.require` -- Protect a method with a permission
+===========================================================
+
+:func:`grok.adapter/grok.implementer` -- Declare an adapter factory
+====================================================================
+
+.. XXX these two decorators are always used together, but are named separately because they are separate in the Zope 3 API. Should grok implement this as one decorator with two arguments?
+
+These decorators are always used in tandem to declare an adapter factory.
+
+.. function:: grok.adapter(*interfaces) 
+
+`*interfaces` -- the interfaces *adapted* by the object created by this factory.
+
+.. function:: grok.implementer(interface) 
+
+`interface` -- the interface *provided* by the object created by this factory.
+
+
+**Example 1:** ::
+
+	@grok.adapter(ICave)
+	@grok.implementer(IHome)
+	def home_for_cave(cave):
+	    return Home()
+
+**Example 2: adapt a regular class instead of an interface ** ::
+
+	@grok.adapter(Cave)
+	@grok.implementer(IHome)
+	def home_for_cave(cave):
+	    return Home()
+
+**Example 3: declare a multi-adapter factory ** ::
+
+	@grok.adapter(ICave,IFire)
+	@grok.implementer(ICozy)
+	def cozy_dwelling(cave, fire):
+	    return Dwelling()
+
+
+
+
+
+
+



More information about the Checkins mailing list