source: weblion/

Last change on this file was 6690, checked in by ewr119, 6 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
1"""Display Subversion URLs in the Browse Source section."""
3import re
5from genshi.builder import tag
6from trac.core import *
7from trac.config import Option
8from trac.web import IRequestFilter
9from import add_ctxtnav
11def prepend_ctxtnav(req, elm_or_label, href, title=None):
12    """Prepend an entry to the current page's ctxtnav bar.
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'ctxtnav', []).insert(0, elm)
19class BrowserLinkAdder(Component):
20    implements(IRequestFilter)
22    svn_base_url = Option('svn', 'repository_url',
23                          doc="base URL of svn repository")
24    pattern = re.compile(r'/browser(/.*|$)')
26    def url(self, path):
27        return u'/'.join((self.svn_base_url.rstrip(u'/'), path.lstrip(u'/')))
29    ### IRequestFilter methods
31    def pre_process_request(self, req, handler):
32        """Do nothing."""
33        return handler
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(, title="This location in the Subversion repository")
40        return template, data, content_type
Note: See TracBrowser for help on using the repository browser.