Edgewall Software

Changes between Version 2 and Version 3 of TracDev/PluginDevelopment/ExtensionPoints/trac.web.chrome.INavigationContributor


Ignore:
Timestamp:
Aug 21, 2011, 10:18:23 PM (13 years ago)
Author:
Peter Suter
Comment:

Replace minimal example with more meaningful ComponentModuleExamples

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment/ExtensionPoints/trac.web.chrome.INavigationContributor

    v2 v3  
    3131== Examples ==
    3232
    33 The following example adds an item to the main navigation bar, named 'sample'. It is rendered as a hyperlink ''Sample'' referencing a resource ''./sample/''. (Assume some other component implements a request handler for this resource and requests the permission 'SAMPLE_VIEW'.)
     33A INavigationContributor in isolation is not very useful and usually accompanied by implementations of other interfaces. Hence the following example is best understood in context of the ComponentModuleExamples.
    3434
     35In Trac, there is no navigation bar item for [TicketComponent components]. The following example implementation adds such an item to the main navigation bar:
    3536{{{#!python
    3637from trac.core import implements, Component
    3738from trac.web.chrome import INavigationContributor
    3839
    39 class SampleNavigationContributor(Component):
     40class ComponentModule(Component):
    4041
    4142    implements(INavigationContributor)
     
    4445
    4546    def get_active_navigation_item(self, req):
    46         return 'sample'
     47        return 'component'
    4748
    4849    def get_navigation_items(self, req):
    49         if 'SAMPLE_VIEW' in req.perm:
    50             yield ('mainnav', 'sample',
    51                    tag.a(_("Sample"), href=req.href.sample()))
     50        if 'COMPONENT_LIST' in req.perm:
     51            yield ('mainnav', 'component',
     52                   tag.a(_("Components"), href=req.href.component()))
    5253}}}
     54''(Missing here are at least implementations of [../trac.web.api.IRequestHandler IRequestHandler] for the linked URL `./component` that activates this item and [../trac.perm.IPermissionRequestor IPermissionRequestor] for the required permission `COMPONENT_LIST`.)''
    5355
    5456== Available Implementations ==