Changes between Version 2 and Version 3 of TracDev/PluginDevelopment/ExtensionPoints/trac.web.chrome.INavigationContributor
- Timestamp:
- Aug 21, 2011, 10:18:23 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/PluginDevelopment/ExtensionPoints/trac.web.chrome.INavigationContributor
v2 v3 31 31 == Examples == 32 32 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'.) 33 A 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. 34 34 35 In Trac, there is no navigation bar item for [TicketComponent components]. The following example implementation adds such an item to the main navigation bar: 35 36 {{{#!python 36 37 from trac.core import implements, Component 37 38 from trac.web.chrome import INavigationContributor 38 39 39 class SampleNavigationContributor(Component):40 class ComponentModule(Component): 40 41 41 42 implements(INavigationContributor) … … 44 45 45 46 def get_active_navigation_item(self, req): 46 return ' sample'47 return 'component' 47 48 48 49 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())) 52 53 }}} 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`.)'' 53 55 54 56 == Available Implementations ==