Trac is being migrated to new services! Issues can be found in our new YouTrack instance and WIKI pages can be found on our website.

LocalTracChanges: viewmtn_revision_links.py

File viewmtn_revision_links.py, 1.5 KB (added by datallah, 15 years ago)

Plugin to linkify mtn revisions and point them to viewmtn

Line 
1
2from genshi.builder import tag
3
4from trac.core import *
5from trac.util.text import shorten_line
6from trac.wiki.api import IWikiSyntaxProvider
7
8
9#This is a combination of the revision_links sample plugin and ChangesetModule from web_ui/changeset.py
10
11class ViewMTNRevisionLinks(Component):
12    """Adds a few more ways to refer to changesets."""
13
14    implements(IWikiSyntaxProvider)
15
16    KEYWORDS = ['[Rr]ev(?:ision)?', '[Cc]hangeset']
17
18    CHANGESET_ID = r"(?:[a-fA-F\d]{40})" # only hexa ids with the right length
19
20    # IWikiSyntaxProvider methods
21
22    def get_wiki_syntax(self):
23
24        yield (
25            r"r?%s" % (self.CHANGESET_ID),
26            lambda x, y, z:
27            self._format_revision_link(x, 'changeset',
28                y[0] == 'r' and y[1:] or y, y, z))
29
30        def revlink(f, match, fullmatch):
31            rev = match.split(' ', 1)[1] # ignore keyword
32            return self._format_revision_link(f, 'changeset', rev, rev,
33                                              fullmatch)
34        yield (r"!?(?:%s)\s+%s" % ("|".join(self.KEYWORDS),
35                                   self.CHANGESET_ID),
36               revlink)
37
38    def get_link_resolvers(self):
39        yield ('revision', self._format_revision_link)
40
41
42    def _get_viewmtn_url(self, rev):
43        return "/viewmtn/revision/info/%s" % rev
44
45    def _format_revision_link(self, formatter, ns, rev, label, fullmatch=None):
46        return tag.a(label, class_="changeset",
47                 title=shorten_line(rev),
48                 href=self._get_viewmtn_url(rev))
49
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!