1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
Inline Help System
==================
The inline help system offers a base implementation for help folder called
HelpFolder. They make it easy for components to register directories
containing inline help documentation.
These are lazr.folder.ExportedFolder that automatically export
their subdirectories.
>>> from canonical.lazr.folder import ExportedFolder
>>> from lp.services.inlinehelp.browser import HelpFolder
>>> issubclass(HelpFolder, ExportedFolder)
True
>>> HelpFolder.export_subdirectories
True
ZCML Registration
-----------------
HelpFolder can be easily registered using a ZCML directive. The directive
takes the directory served by the HelpFolder and the request type for which
it should be registered.
>>> import tempfile
>>> help_folder = tempfile.mkdtemp(prefix='help')
>>> from zope.configuration import xmlconfig
>>> zcmlcontext = xmlconfig.string("""
... <configure xmlns:lp="http://namespaces.canonical.com/lp">
... <include package="lp.services.inlinehelp" file="meta.zcml" />
... <lp:help-folder folder="%s"/>
... </configure>
... """ % help_folder)
The help folder is registered on the ILaunchpadRoot interface.
>>> from zope.interface import directlyProvides
>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> class FakeRequest:
... pass
>>> request = FakeRequest()
>>> directlyProvides(request, IBrowserRequest)
>>> from zope.component import queryMultiAdapter
>>> from canonical.launchpad.webapp.publisher import rootObject
>>> help = queryMultiAdapter((rootObject, request), name="+help")
>>> help.folder == help_folder
True
>>> isinstance(help, HelpFolder)
True
The help folder can also be registered for a specific request type using the
"type" attribute.
>>> from zope.publisher.interfaces.http import IHTTPRequest
>>> directlyProvides(request, IHTTPRequest)
>>> print queryMultiAdapter((rootObject, request), name="+help")
None
>>> zcmlcontext = xmlconfig.string("""
... <configure
... xmlns:lp="http://namespaces.canonical.com/lp">
... <include package="lp.services.inlinehelp" file="meta.zcml" />
... <lp:help-folder folder="%s"
... type="zope.publisher.interfaces.http.IHTTPRequest"/>
... </configure>
... """ % help_folder)
>>> queryMultiAdapter((rootObject, request), name="+help")
<lp.services...>
Cleanup
-------
>>> from zope.testing.cleanup import cleanUp
>>> cleanUp()
>>> import shutil
>>> shutil.rmtree(help_folder)
|