source: main/waeup.ikoba/trunk/src/waeup/ikoba/doctests/app.txt @ 17929

Last change on this file since 17929 was 12993, checked in by Henrik Bettermann, 9 years ago

First adjustments for the upcoming Ikoba User Handbook.

File size: 2.8 KB
RevLine 
[12993]1Central Components
2******************
[3933]3
[5140]4.. :doctest:
[11949]5.. :layer: waeup.ikoba.testing.IkobaUnitTestLayer
[3933]6
[11949]7.. module:: waeup.ikoba.app
[3933]8
[4273]9
[11954]10Creating `Company` instances
[11971]11============================
[3933]12
[11954]13As :class:`Company` instances make use of the Zope Component
[4273]14Architecture (ZCA), we have to setup the basic component registries,
15before we can create instances. We do this by simply grokking the
16whole :mod:`waeup` package. This way all interfaces, utilities and adapters
17defined in the package are looked up and registered with the global
[5140]18registries (this is done by the testlayer automatically).
[3933]19
[11954]20Now we can import the :class:`Company` class and create an
[4273]21instance:
[3933]22
[11954]23    >>> from waeup.ikoba.app import Company
24    >>> mycompany = Company()
25    >>> mycompany
26    <waeup.ikoba.app.Company object at 0x...>
[3933]27
[11954]28Instances of `Company` comply with the interface
29`waeup.ikoba.interfaces.ICompany`:
[3933]30
31    >>> from zope.interface.verify import verifyClass
[11954]32    >>> from waeup.ikoba.interfaces import ICompany
33    >>> verifyClass(ICompany, Company)
[3933]34    True
35
[4273]36A freshly created instance provides the attributes promised by the
37interface:
[3933]38
[11954]39    >>> from waeup.ikoba.app import Company
40    >>> mycompany = Company()
41    >>> mycompany['configuration'].name
42    u'Sample Company'
[3933]43
[11954]44  >>> mycompany['users']
[11949]45  <waeup.ikoba.userscontainer.UsersContainer object at 0x...>
[6897]46
[11954]47  >>> mycompany['datacenter']
[11949]48  <waeup.ikoba.datacenter.DataCenter object at 0x...>
[6897]49
[11954]50  >>> mycompany['configuration']
[11949]51  <waeup.ikoba.configuration.ConfigurationContainer object at 0x...>
[6907]52
[6897]53
[11949]54Ikoba plugins
[11971]55=============
[6897]56
[11949]57waeup.ikoba provides an API to 'plugin' components. Things that should
58be setup at creation time of a Ikoba application can indicate
59that by providing a utility providing IIkobaPlugin.
[6897]60
61The plugins are looked up by an created app, which then will call the
62``setup()`` method of each plugin.
63
[11949]64   >>> from waeup.ikoba.interfaces import IIkobaPluggable
[6897]65   >>> from zope.component import getAdapters, getUtilitiesFor
[11949]66   >>> sorted(list(getUtilitiesFor(IIkobaPluggable)))
[12209]67   [(u'documents', <waeup.ikoba.documents.container.DocumentsPlugin ...)]
[6897]68
69
70We can provide a new plugin like this:
71
72   >>> import grok
[11949]73   >>> from waeup.ikoba.interfaces import IIkobaPluggable
[6897]74   >>> class MyPlugin(grok.GlobalUtility):
[11949]75   ...   grok.implements(IIkobaPluggable)
[6897]76   ...   def setup(self, site, name, logger):
77   ...     print "Setup was called for"
78   ...     print site
79   ...   def update(self, site, name, logger):
80   ...     pass
81
82When we register the plugin
83
84   >>> grok.testing.grok_component('MyPlugin', MyPlugin)
85   True
86
[11949]87and setup a new Ikoba instance, we will get a message:
[6897]88
[11954]89   >>> from waeup.ikoba.app import Company
90   >>> site = Company()
[6897]91   Setup was called for
[11954]92   <waeup.ikoba.app.Company object at 0x...>
[6897]93
[11954]94Apparently the plugin can do with the Company object whatever it
[7811]95likes. That's what plugins are for.
Note: See TracBrowser for help on using the repository browser.