\chapter{Components}

The \module{grok} module defines a set of components that provide basic Zope 3
functionality in a convenient way.

\section{\class{grok.Adapter}}

  Implementation, configuration, and registration of Zope 3 adapters.

  \begin{classdesc*}{grok.Adapter}
    Base class to define an adapter. Adapters are automatically registered when
    a module is "grokked".

    \begin{memberdesc}{context}
      The adapted object.
    \end{memberdesc}

  \begin{bf}Directives:\end{bf}

  \begin{itemize}
    \item[\function{grok.context(context_obj_or_interface)}] Maybe required.
    Identifies the type of objects or interface for the adaptation.

    If Grok can determine a context for adaptation from the module, this
    directive can be omitted. If the automatically determined context is not
    correct, or if no context can be derived from the module the directive is
    required.

    \item[\function{grok.implements(*interfaces)}] Required. Identifies the
    interface(s) the adapter implements.

    \item[\function{grok.name(name)}] Optional. Identifies the name used for
    the adapter registration. If ommitted, no name will be used.

    When a name is used for the adapter registration, the adapter can only be
    retrieved by explicitely using its name.

    \item[\function{grok.provides(name)}] Maybe required. If the adapter
    implements more than one interface, \function{grok.provides} is required to
    disambiguate for what interface the adapter will be registered.
  \end{itemize}
  \end{classdesc*}

  \begin{bf}Example:\end{bf}

  \begin{verbatim}
import grok
from zope import interface

class Cave(grok.Model):
    pass

class IHome(interface.Interface):
    pass

class Home(grok.Adapter):
    grok.implements(IHome)

home = IHome(cave)
  \end{verbatim}

  \begin{bf}Example 2:\end{bf}

  \begin{verbatim}
import grok
from zope import interface

class Cave(grok.Model):
    pass

class IHome(interface.Interface):
    pass

class Home(grok.Adapter):
    grok.implements(IHome)
    grok.name('home')

from zope.component import getAdapter
home = getAdapter(cave, IHome, name='home')
  \end{verbatim}

\section{\class{grok.AddForm}}

\section{\class{grok.Annotation}}

\section{\class{grok.Application}}

\section{grok.ClassGrokker}

\section{\class{grok.Container}}

  \begin{classdesc*}{grok.Container}
    Mixin base class to define a container object. The container implements the
    zope.app.container.interfaces.IContainer interface using a BTree, providing
    reasonable performance for large collections of objects.
  \end{classdesc*}

\section{\class{grok.DisplayForm}}

\section{\class{grok.EditForm}}

\section{\class{grok.Form}}

\section{\class{grok.GlobalUtility}}

  \begin{classdesc*}{grok.GlobalUtility}
    Base class to define a globally registered utility. Global utilities are
    automatically registered when a module is "grokked".

  \begin{bf}Directives:\end{bf}

  \begin{itemize}
    \item[\function{grok.implements(*interfaces)}] Required. Identifies the
    interfaces(s) the utility implements.

    \item[\function{grok.name(name)}] Optional. Identifies the name used for
    the adapter registration. If ommitted, no name will be used.

    When a name is used for the global utility registration, the global utility
    can only be retrieved by explicitely using its name.

    \item[\function{grok.provides(name)}] Maybe required. If the global utility
    implements more than one interface, \function{grok.provides} is required to
    disambiguate for what interface the global utility will be registered.
  \end{itemize}
  \end{classdesc*}

\section{\class{grok.Indexes}}

\section{grok.InstanceGrokker}

\section{\class{grok.JSON}}

\section{\class{grok.LocalUtility}}

  \begin{classdesc*}{grok.LocalUtility}
    Base class to define a utility that will be registered local to a
    \class{grok.Site} or \class{grok.Application} object by using the
    \function{grok.local_utility} directive.

  \begin{bf}Directives:\end{bf}

  \begin{itemize}
    \item[\function{grok.implements(*interfaces)}] Optional. Identifies the
    interfaces(s) the utility implements.

    \item[\function{grok.name(name)}] Optional. Identifies the name used for
    the adapter registration. If ommitted, no name will be used.

    When a name is used for the local utility registration, the local utility
    can only be retrieved by explicitely using its name.

    \item[\function{grok.provides(name)}] Maybe required. If the local utility
    implements more than one interface or if the implemented interface cannot
    be determined, \function{grok.provides} is required to disambiguate for
    what interface the local utility will be registered.
  \end{itemize}
  \end{classdesc*}

  \begin{seealso}
  Local utilities need to be registered in the context of \class{grok.Site} or
  \class{grok.Application} using the \function{grok.local_utility} directive.
  \end{seealso}

\section{\class{grok.Model}}

  Base class to define an application "content" or model object. Model objects
  provide persistence and containment.

\section{grok.ModuleGrokker}

\section{\class{grok.MultiAdapter}}

  \begin{classdesc*}{grok.MultiAdapter}
    Base class to define a multi adapter. MultiAdapters are automatically
    registered when a module is "grokked".

  \begin{bf}Directives:\end{bf}

  \begin{itemize}
    \item[\function{grok.adapts(*objects_or_interfaces)}] Required. Identifies
    the combination of types of objects or interfaces for the adaptation.

    \item[\function{grok.implements(*interfaces)}] Required. Identifies the
    interfaces(s) the adapter implements.

    \item[\function{grok.name(name)}] Optional. Identifies the name used for
    the adapter registration. If ommitted, no name will be used.

    When a name is used for the adapter registration, the adapter can only
    be retrieved by explicitely using its name.

    \item[\function{grok.provides(name)}] Maybe required. If the adapter
    implements more than one interface, \function{grok.provides} is required to
    disambiguate for what interface the adapter will be registered.
  \end{itemize}
  \end{classdesc*}

  \begin{bf}Example:\end{bf}

  \begin{verbatim}
import grok
from zope import interface

class Fireplace(grok.Model):
    pass

class Cave(grok.Model):
    pass

class IHome(interface.Interface):
    pass

class Home(grok.MultiAdapter):
    grok.adapts(Cave, Fireplace)
    grok.implements(IHome)

    def __init__(self, cave, fireplace):
        self.cave = cave
        self.fireplace = fireplace

home = IHome(cave, fireplace)
  \end{verbatim}

\section{grok.PageTemplate}

\section{grok.PageTemplateFile}

\section{\class{grok.Site}}

  Base class to define an site object. Site objects provide persistence and
  containment.

\section{\class{grok.Traverser}}

\section{\class{grok.View}}

\section{\class{grok.XMLRPC}}
