~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/templatefunctions.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-09 03:41:07 UTC
  • mfrom: (345.2.8 valid-feed)
  • Revision ID: mnordhoff@mattnordhoff.com-20090609034107-khjku04mzj36vumr
Make the Atom feeds (nearly) valid (bug #247162)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This program is free software; you can redistribute it and/or modify
 
3
# it under the terms of the GNU General Public License as published by
 
4
# the Free Software Foundation; either version 2 of the License, or
 
5
# (at your option) any later version.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
#
 
16
import cgi
 
17
import os
 
18
from loggerhead.zptsupport import zpt
 
19
 
 
20
 
 
21
templatefunctions = {}
 
22
 
 
23
 
 
24
def templatefunc(func):
 
25
    templatefunctions[func.__name__] = func
 
26
    return func
 
27
 
 
28
 
 
29
_base = os.path.dirname(__file__)
 
30
 
 
31
 
 
32
def _pt(name):
 
33
    return zpt(os.path.join(_base, 'templates', name + '.pt'))
 
34
 
 
35
 
 
36
templatefunctions['macros'] = _pt('macros').macros
 
37
templatefunctions['breadcrumbs'] = _pt('breadcrumbs').macros
 
38
 
 
39
 
 
40
@templatefunc
 
41
def file_change_summary(url, entry, file_changes, style='normal', currently_showing=None):
 
42
    if style == 'fragment':
 
43
        def file_link(filename):
 
44
            if currently_showing and filename == currently_showing:
 
45
                return '<b><a href="#%s">%s</a></b>' % (
 
46
                    cgi.escape(filename), cgi.escape(filename))
 
47
            else:
 
48
                return revision_link(
 
49
                    url, entry.revno, filename, '#' + filename)
 
50
    else:
 
51
        def file_link(filename):
 
52
            return '<a href="%s%s" title="View changes to %s in revision %s">%s</a>'%(
 
53
                url(['/revision', entry.revno]), '#' + filename, cgi.escape(filename),
 
54
                cgi.escape(entry.revno), cgi.escape(filename))
 
55
    return _pt('revisionfilechanges').expand(
 
56
        entry=entry, file_changes=file_changes, file_link=file_link, **templatefunctions)
 
57
 
 
58
 
 
59
@templatefunc
 
60
def revisioninfo(url, branch, entry, file_changes=None, currently_showing=None, merged_in=None):
 
61
    from loggerhead import util
 
62
    return _pt('revisioninfo').expand(
 
63
        url=url, change=entry, branch=branch, util=util,
 
64
        file_changes=file_changes, currently_showing=currently_showing,
 
65
        merged_in=merged_in, **templatefunctions)
 
66
 
 
67
 
 
68
@templatefunc
 
69
def branchinfo(branch):
 
70
    if branch.served_url is not None:
 
71
        return _pt('branchinfo').expand(branch=branch, **templatefunctions)
 
72
    else:
 
73
        return ''
 
74
 
 
75
 
 
76
@templatefunc
 
77
def collapse_button(group, name, branch, normal='block'):
 
78
    return _pt('collapse-button').expand(
 
79
        group=group, name=name, normal=normal, branch=branch,
 
80
        **templatefunctions)
 
81
 
 
82
 
 
83
@templatefunc
 
84
def collapse_all_button(group, branch, normal='block'):
 
85
    return _pt('collapse-all-button').expand(
 
86
        group=group, normal=normal, branch=branch,
 
87
        **templatefunctions)
 
88
 
 
89
 
 
90
@templatefunc
 
91
def revno_with_nick(entry):
 
92
    if entry.branch_nick:
 
93
        extra = ' ' + entry.branch_nick
 
94
    else:
 
95
        extra = ''
 
96
    return '(%s%s)'%(entry.revno, extra)
 
97
 
 
98
 
 
99
@templatefunc
 
100
def search_box(branch, navigation):
 
101
    return _pt('search-box').expand(branch=branch, navigation=navigation,
 
102
        **templatefunctions)
 
103
 
 
104
 
 
105
@templatefunc
 
106
def feed_link(branch, url):
 
107
    return _pt('feed-link').expand(branch=branch, url=url, **templatefunctions)
 
108
 
 
109
 
 
110
@templatefunc
 
111
def menu(branch, url, fileview_active=False):
 
112
    return _pt('menu').expand(branch=branch, url=url,
 
113
        fileview_active=fileview_active, **templatefunctions)
 
114
 
 
115
 
 
116
@templatefunc
 
117
def annotate_link(url, revno, path):
 
118
    return '<a href="%s" title="Annotate %s">%s</a>'%(
 
119
        url(['/annotate', revno, path]), cgi.escape(path), cgi.escape(path))
 
120
 
 
121
@templatefunc
 
122
def revision_link(url, revno, path, frag=''):
 
123
    return '<a href="%s%s" title="View changes to %s in revision %s">%s</a>'%(
 
124
        url(['/revision', revno, path]), frag, cgi.escape(path),
 
125
        cgi.escape(revno), cgi.escape(path))