| 1 | #------------------------------------------------------------------------------ |
|---|
| 2 | # $Id$ |
|---|
| 3 | # $URL$ |
|---|
| 4 | # Copyright (c) 2006, Ilias Lazaridis - All Rights Reserved |
|---|
| 5 | #------------------------------------------------------------------------------ |
|---|
| 6 | |
|---|
| 7 | import re |
|---|
| 8 | |
|---|
| 9 | from trac.core import * |
|---|
| 10 | from trac.web.chrome import INavigationContributor |
|---|
| 11 | from trac.util.html import html |
|---|
| 12 | |
|---|
| 13 | #------------------------------------------------------------------------------ |
|---|
| 14 | |
|---|
| 15 | class ProjectNavigation(Component): |
|---|
| 16 | implements(INavigationContributor) |
|---|
| 17 | |
|---|
| 18 | # INavigationContributor methods |
|---|
| 19 | def get_active_navigation_item(self, req): |
|---|
| 20 | return '' |
|---|
| 21 | |
|---|
| 22 | def get_navigation_items(self, req): |
|---|
| 23 | yield 'projnav', 'project', html.a( 'Project', href=req.href.wiki('ProjectGuide') ) |
|---|
| 24 | yield 'projnav', 'product', html.a( 'Product', href=req.href.wiki('ProductGuide') ) |
|---|
| 25 | yield 'projnav', 'license', html.a( 'License', href=req.href.wiki('ProjectLicense') ) |
|---|
| 26 | yield 'projnav', 'services', html.a( 'Services', href=req.href.wiki('CommercialServices') ) |
|---|
| 27 | yield 'mainnav', 'plans', html.a( 'Plans', href=req.href.wiki('WorkingPlans') ) |
|---|
| 28 | |
|---|
| 29 | #------------------------------------------------------------------------------ |
|---|
| 30 | |
|---|
| 31 | class NavigationOrder(Component): |
|---|
| 32 | """ implements a generic way to define the order of navigation items |
|---|
| 33 | |
|---|
| 34 | [navigation-order] |
|---|
| 35 | projnav = guide, license, plans, services, |
|---|
| 36 | usernav = x, y, z |
|---|
| 37 | ... (define your own navigation_sets) |
|---|
| 38 | |
|---|
| 39 | """ |
|---|
| 40 | |
|---|
| 41 | implements(INavigationContributor) |
|---|
| 42 | |
|---|
| 43 | def _get_navigation_orders(self): |
|---|
| 44 | |
|---|
| 45 | # retrieve all available categories from *.ini section |
|---|
| 46 | config = self.config['navigation-order'] |
|---|
| 47 | navorders = {} |
|---|
| 48 | for category, value in config.options(): |
|---|
| 49 | navorders[category] = config.getlist(category, sep=',') |
|---|
| 50 | |
|---|
| 51 | # retrieve the chrome component |
|---|
| 52 | from trac.web.chrome import Chrome |
|---|
| 53 | chrome = Chrome(self.env) |
|---|
| 54 | |
|---|
| 55 | # insert the categeries as attributes |
|---|
| 56 | # further processing from within the chrome component |
|---|
| 57 | for category, order in navorders.iteritems(): |
|---|
| 58 | setattr(chrome, category + '_order', order) |
|---|
| 59 | |
|---|
| 60 | self.log.debug("loaded navigation category: %s", category) |
|---|
| 61 | |
|---|
| 62 | def get_active_navigation_item(self, req): |
|---|
| 63 | return 'dummy' |
|---|
| 64 | |
|---|
| 65 | def get_navigation_items(self, req): |
|---|
| 66 | yield 'dummynav', 'dummy', 'dummy' |
|---|
| 67 | #WORKAROUND: cannot use __init__ alone, see trac:#4190 |
|---|
| 68 | #verification: remove INavigationContributor, activate call in __init__ |
|---|
| 69 | self._get_navigation_orders() |
|---|
| 70 | |
|---|
| 71 | def __init__(self): |
|---|
| 72 | #self._get_navigation_orders() |
|---|
| 73 | pass |
|---|
| 74 | |
|---|
| 75 | #------------------------------------------------------------------------------ |
|---|
| 76 | |
|---|
| 77 | class WikiBacklinks(Component): |
|---|
| 78 | implements(INavigationContributor) |
|---|
| 79 | |
|---|
| 80 | # INavigationContributor methods |
|---|
| 81 | def get_active_navigation_item(self, req): |
|---|
| 82 | return '' |
|---|
| 83 | |
|---|
| 84 | def get_navigation_items(self, req): |
|---|
| 85 | import AutoNav |
|---|
| 86 | if ( req.path_info.startswith('/wiki') ): |
|---|
| 87 | # wiki page name is not yet within hdf, thus extract |
|---|
| 88 | match = re.match(r'^/wiki(?:/(.*))?', req.path_info) |
|---|
| 89 | if match: |
|---|
| 90 | if match.group(1): |
|---|
| 91 | req.hdf['wiki.page_name'] = match.group(1) |
|---|
| 92 | else: |
|---|
| 93 | req.hdf['wiki.page_name'] = '--Empty--' |
|---|
| 94 | |
|---|
| 95 | backlinks = AutoNav.execute(req.hdf, '', self.env) |
|---|
| 96 | |
|---|
| 97 | for name in backlinks: |
|---|
| 98 | yield 'backlinks', name, html.a( name, href=req.href.wiki(name) ) |
|---|
| 99 | |
|---|
| 100 | #------------------------------------------------------------------------------ |
|---|
| 101 | |
|---|
| 102 | class CustomCss(Component): |
|---|
| 103 | from trac.web.chrome import ITemplateProvider, add_stylesheet |
|---|
| 104 | from trac.web.api import IRequestFilter |
|---|
| 105 | |
|---|
| 106 | implements(ITemplateProvider, IRequestFilter) |
|---|
| 107 | |
|---|
| 108 | def __init__(self): |
|---|
| 109 | import patch |
|---|
| 110 | |
|---|
| 111 | # ITemplateProvider methods |
|---|
| 112 | def get_templates_dirs(self): |
|---|
| 113 | """ |
|---|
| 114 | Return the absolute path of the directory containing the provided |
|---|
| 115 | ClearSilver templates. |
|---|
| 116 | """ |
|---|
| 117 | from pkg_resources import resource_filename |
|---|
| 118 | # return [resource_filename(__name__, 'templates')] |
|---|
| 119 | return '' |
|---|
| 120 | |
|---|
| 121 | def get_htdocs_dirs(self): |
|---|
| 122 | """Return the absolute path of a directory containing additional |
|---|
| 123 | static resources (such as images, style sheets, etc). |
|---|
| 124 | """ |
|---|
| 125 | from pkg_resources import resource_filename |
|---|
| 126 | return [('tracx', resource_filename(__name__, 'htdocs'))] |
|---|
| 127 | |
|---|
| 128 | def pre_process_request(self, req, handler): |
|---|
| 129 | """Do any pre-processing the request might need; typically adding |
|---|
| 130 | values to req.hdf, or redirecting. |
|---|
| 131 | |
|---|
| 132 | Always returns the request handler, even if unchanged. |
|---|
| 133 | """ |
|---|
| 134 | |
|---|
| 135 | from trac.web.chrome import add_stylesheet |
|---|
| 136 | add_stylesheet(req, 'tracx/css/trac.css') |
|---|
| 137 | add_stylesheet(req, 'tracx/css/size.css') |
|---|
| 138 | |
|---|
| 139 | return(handler) |
|---|
| 140 | |
|---|
| 141 | def post_process_request(self, req, template, content_type): |
|---|
| 142 | """Do any post-processing the request might need; typically adding |
|---|
| 143 | values to req.hdf, or changing template or mime type. |
|---|
| 144 | |
|---|
| 145 | Always returns a tuple of (template, content_type), even if |
|---|
| 146 | unchanged. |
|---|
| 147 | """ |
|---|
| 148 | |
|---|
| 149 | return(template, content_type) |
|---|
| 150 | |
|---|
| 151 | #------------------------------------------------------------------------------ |
|---|