source: weblion/weblion.psu.edu/subversionlocationplugin/trunk/subversionlocation/web_ui.py

Last change on this file was 6690, checked in by ewr119, 5 years ago
  • Now puts the Subversion Location link back on the left, where it won't throw off people's muscle memory. Closes #1104 again.
  • Egg depends on Trac and Genshi again now. Added classifiers.
  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1"""Display Subversion URLs in the Browse Source section."""
2
3import re
4
5from genshi.builder import tag
6from trac.core import *
7from trac.config import Option
8from trac.web import IRequestFilter
9from trac.web.chrome import add_ctxtnav
10
11def prepend_ctxtnav(req, elm_or_label, href, title=None):
12    """Prepend an entry to the current page's ctxtnav bar.
13   
14    add_ctxtnav(), sadly, always appends to the right side of the (right-aligned by default) context nav, changing the onscreen locations of the links people are already used to.
15    """
16    elm = tag.a(elm_or_label, href=href, title=title)
17    req.chrome.setdefault('ctxtnav', []).insert(0, elm)
18
19class BrowserLinkAdder(Component):
20    implements(IRequestFilter)
21
22    svn_base_url = Option('svn', 'repository_url',
23                          doc="base URL of svn repository")
24    pattern = re.compile(r'/browser(/.*|$)')
25
26    def url(self, path):
27        return u'/'.join((self.svn_base_url.rstrip(u'/'), path.lstrip(u'/')))
28
29    ### IRequestFilter methods
30   
31    def pre_process_request(self, req, handler):
32        """Do nothing."""
33        return handler
34   
35    def post_process_request(self, req, template, data, content_type):
36        """Stick the Subversion Location link in the contextual nav when applicable."""
37        match = self.pattern.match(req.path_info)
38        if match:
39            prepend_ctxtnav(req, 'Subversion Location', self.url(match.group(1)), title="This location in the Subversion repository")
40        return template, data, content_type
Note: See TracBrowser for help on using the repository browser.