Edgewall Software

source: trunk/svntrac/Module.py@ 1

Last change on this file since 1 was 1, checked in by Jonas Borgström, 20 years ago

Initial import

File size: 2.4 KB
Line 
1# svntrac
2#
3# Copyright (C) 2003 Xyche Software
4#
5# svntrac is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of the
8# License, or (at your option) any later version.
9#
10# svntrac is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18#
19# Author: Jonas Borgström <jonas@xyche.com>
20
21import os
22import StringIO
23from Toolbar import Toolbar
24
25class Module:
26 def __init__(self, config, args, pool):
27 self.config = config
28 self.args = args
29 self.pool = pool
30
31 self.toolbar = Toolbar()
32
33 self.namespace = {}
34 self.namespace['title'] = ''
35 self.namespace['svntrac_url'] = 'http://svntrac.xyche.com/'
36 self.namespace['htdocs_location'] = config.get('general',
37 'htdocs_location')
38
39 def render (self):
40 """
41 this function can be overridden to fill self.namespace with
42 useful content.
43 """
44 pass
45
46 def apply_template (self):
47 svntrac_home = self.config.get('general', 'svntrac_home')
48 tmpl_filename = self.config.get('templates', self.template_key)
49 tmpl_filename = os.path.join (svntrac_home, tmpl_filename)
50
51 self.namespace['toolbar'] = self.toolbar.render ()
52
53 header_tmpl = self.config.get('templates', 'header_template')
54 footer_tmpl = self.config.get('templates', 'footer_template')
55 header_tmpl = os.path.join (svntrac_home, header_tmpl)
56 footer_tmpl = os.path.join (svntrac_home, footer_tmpl)
57
58 header = open(header_tmpl).read()
59 footer = open(footer_tmpl).read()
60
61 self.namespace['header'] = header % self.namespace
62 self.namespace['footer'] = footer % self.namespace
63 template = open(tmpl_filename).read ()
64 # Apply the template
65 out = template % self.namespace
66 print 'Content-type: text/html\r\n\r\n'
67 print out
68
Note: See TracBrowser for help on using the repository browser.