~ubuntu-branches/ubuntu/jaunty/trac/jaunty

« back to all changes in this revision

Viewing changes to sample-plugins/revision_links.py

  • Committer: Bazaar Package Importer
  • Author(s): Luis Matos
  • Date: 2008-07-13 23:46:20 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080713234620-13ynpdpkbaymfg1z
Tags: 0.11-2
* Re-added python-setup-tools to build dependences. Closes: #490320 #468705
* New upstream release Closes: 489727
* Added sugestion for other vcs support available: git bazaar mercurial 
* Added spamfilter plugin to sugests
* Moved packaging from python-support to python-central
* Added an entry to the NEWS about the cgi Closes: #490275
* Updated 10_remove_trac_suffix_from_title patch to be used in 0.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: 6326 $"
 
12
url = "$URL: http://svn.edgewall.org/repos/trac/branches/0.11-stable/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")