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

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

First adjustments for the upcoming Ikoba User Handbook.

File size: 2.8 KB
Line 
1Central Components
2******************
3
4.. :doctest:
5.. :layer: waeup.ikoba.testing.IkobaUnitTestLayer
6
7.. module:: waeup.ikoba.app
8
9
10Creating `Company` instances
11============================
12
13As :class:`Company` instances make use of the Zope Component
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
18registries (this is done by the testlayer automatically).
19
20Now we can import the :class:`Company` class and create an
21instance:
22
23    >>> from waeup.ikoba.app import Company
24    >>> mycompany = Company()
25    >>> mycompany
26    <waeup.ikoba.app.Company object at 0x...>
27
28Instances of `Company` comply with the interface
29`waeup.ikoba.interfaces.ICompany`:
30
31    >>> from zope.interface.verify import verifyClass
32    >>> from waeup.ikoba.interfaces import ICompany
33    >>> verifyClass(ICompany, Company)
34    True
35
36A freshly created instance provides the attributes promised by the
37interface:
38
39    >>> from waeup.ikoba.app import Company
40    >>> mycompany = Company()
41    >>> mycompany['configuration'].name
42    u'Sample Company'
43
44  >>> mycompany['users']
45  <waeup.ikoba.userscontainer.UsersContainer object at 0x...>
46
47  >>> mycompany['datacenter']
48  <waeup.ikoba.datacenter.DataCenter object at 0x...>
49
50  >>> mycompany['configuration']
51  <waeup.ikoba.configuration.ConfigurationContainer object at 0x...>
52
53
54Ikoba plugins
55=============
56
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.
60
61The plugins are looked up by an created app, which then will call the
62``setup()`` method of each plugin.
63
64   >>> from waeup.ikoba.interfaces import IIkobaPluggable
65   >>> from zope.component import getAdapters, getUtilitiesFor
66   >>> sorted(list(getUtilitiesFor(IIkobaPluggable)))
67   [(u'documents', <waeup.ikoba.documents.container.DocumentsPlugin ...)]
68
69
70We can provide a new plugin like this:
71
72   >>> import grok
73   >>> from waeup.ikoba.interfaces import IIkobaPluggable
74   >>> class MyPlugin(grok.GlobalUtility):
75   ...   grok.implements(IIkobaPluggable)
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
87and setup a new Ikoba instance, we will get a message:
88
89   >>> from waeup.ikoba.app import Company
90   >>> site = Company()
91   Setup was called for
92   <waeup.ikoba.app.Company object at 0x...>
93
94Apparently the plugin can do with the Company object whatever it
95likes. That's what plugins are for.
Note: See TracBrowser for help on using the repository browser.