Software Freedom Law Center

root/trunk/trac/sample-plugins/revision_links.py

Revision 46, 1.7 kB (checked in by bkuhn, 11 months ago)

I am keeping a temporary fork of trac as I work on various changes to
it. I'll be coordinating with their mailing list soon.

Line 
1 """Sample Wiki syntax extension plugin."""
2
3 from genshi.builder import tag
4
5 from trac.core import *
6 from trac.util.text import shorten_line
7 from trac.versioncontrol.api import NoSuchChangeset
8 from trac.versioncontrol.web_ui import ChangesetModule
9 from trac.wiki.api import IWikiSyntaxProvider
10
11 revision = "$Rev: 2 $"
12 url = "$URL: /mirror/sample-plugins/revision_links.py $"
13
14 class RevisionLinks(Component):
15     """Adds a few more ways to refer to changesets."""
16
17     implements(IWikiSyntaxProvider)
18
19     KEYWORDS = ['[Rr]ev(?:ision)?', '[Cc]hangeset']
20
21     # IWikiSyntaxProvider methods
22
23     def get_wiki_syntax(self):
24         def revlink(f, match, fullmatch):
25             rev = match.split(' ', 1)[1] # ignore keyword
26             return self._format_revision_link(f, 'revision', rev, rev,
27                                               fullmatch)
28
29         yield (r"!?(?:%s)\s+%s" % ("|".join(self.KEYWORDS),
30                                    ChangesetModule.CHANGESET_ID),
31                revlink)
32
33     def get_link_resolvers(self):
34         yield ('revision', self._format_revision_link)
35
36     def _format_revision_link(self, formatter, ns, rev, label, fullmatch=None):
37         rev, params, fragment = formatter.split_link(rev)
38         try:
39             changeset = self.env.get_repository().get_changeset(rev)
40             return tag.a(label, class_="changeset",
41                          title=shorten_line(changeset.message),
42                          href=(formatter.href.changeset(rev) +
43                                params + fragment))
44         except NoSuchChangeset:
45             return tag.a(label, class_="missing changeset",
46                          href=formatter.href.changeset(rev),
47                          rel="nofollow")
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC