Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Package for the creation and management of templates.
9
 
10
package Codestriker::Http::Template;
11
 
12
use strict;
13
use Template;
14
 
15
use Codestriker;
16
 
17
# Create a new template.
18
sub new($$) {
19
    my ($type, $name) = @_;
20
 
21
    my $self = {};
22
    $self->{name} = $name;
23
 
1302 dpurdie 24
    die ("BASEDIR not configured correctly: ". $Codestriker::BASEDIR)
25
        unless ( -d $Codestriker::BASEDIR . '/template'  );
1293 dpurdie 26
    # Template configuration.
27
    my $config = {
28
	    # Location of templates.
29
	    INCLUDE_PATH => 
30
		$Codestriker::BASEDIR . "/template/en/custom:" .
31
		$Codestriker::BASEDIR . "/template/en/default" ,
32
 
33
	    # Remove white-space before template directives
34
	    # (PRE_CHOMP) and at the beginning and end of templates
35
	    # and template blocks (TRIM) for better looking, more
36
	    # compact content.  Use the plus sign at the beginning #
37
	    # of directives to maintain white space (i.e. [%+
38
	    # DIRECTIVE %]).
39
	    PRE_CHOMP => 1,
40
	    TRIM => 1, 
41
 
42
	    # Codestriker-specific plugins.
43
	    PLUGIN_BASE => 'Codestriker::Template::Plugin'
44
    };
45
 
46
    # If the Codestriker tmpdir has been defined, use that for
47
    # location for generating the templates.
48
    if (defined $Codestriker::tmpdir && $Codestriker::tmpdir ne '') {
49
        $config->{COMPILE_DIR} = $Codestriker::tmpdir;
50
    }
51
 
52
    $self->{template} = Template->new($config) || die Template->error();
53
 
54
    return bless $self, $type;
55
}
56
 
57
# Return the template associated with this object.
58
sub get_template($) {
59
    my ($self) = @_;
60
 
61
    return $self->{template};
62
}
63
 
64
# Process the template.  Note the results are stored into a variable, which is
65
# then output to STDOUT.  This is required, as if the HTTP response is a 
66
# compressed stream (which is tied to STDOUT), for some reason, this doesn't
67
# play well with TT's default STDOUT writing.  Storing it to a temporary
68
# variable does the trick.
69
sub process($$) {
70
    my ($self, $vars) = @_;
71
 
72
    # Add into the vars the standard .conf file options. 	
73
 
74
    # Indicate if the "delete" button should be visible or not.
75
    $vars->{'delete_enabled'} = $Codestriker::allow_delete;
76
 
77
    # Indicate if the "list/search" functionality is available or not.
78
    $vars->{'searchlist_enabled'} = $Codestriker::allow_searchlist;
79
 
80
    # Indicate if the "project" functionality is available or not.
81
    $vars->{'projects_enabled'} = Codestriker->projects_disabled() ? 0 : 1;
82
 
83
    # Indicate if bug db integration is enabled.
84
    $vars->{'bugdb_enabled'} =
85
	(defined $Codestriker::bug_db && $Codestriker::bug_db ne "") ? 1 : 0;
86
 
87
    # Indicate if antispam_email is enabled.
88
    $vars->{'antispam_email'} = $Codestriker::antispam_email;
89
 
90
    # CodeStriker Version, used in the title.
91
    $vars->{'version'} = $Codestriker::VERSION;
92
 
93
    $vars->{'main_title'} = $Codestriker::title;
94
 
95
    $vars->{'rss_enabled'} = $Codestriker::rss_enabled;
96
 
97
    # Indicate if the repository field should be displayed.
98
    $vars->{'allow_repositories'} = scalar(@Codestriker::valid_repositories) ? 1 : 0;
99
 
100
    # Display the topic size limit if any.
101
    $vars->{'maximum_topic_size_lines'} = $Codestriker::maximum_topic_size_lines eq "" ? 
102
 
103
                                          $Codestriker::maximum_topic_size_lines;
104
 
105
    $vars->{'suggested_topic_size_lines'} = $Codestriker::suggested_topic_size_lines eq "" ? 
106
 
107
                                          $Codestriker::suggested_topic_size_lines;
108
 
109
    # Determine whether the current topic is 'readonly'; this determines
110
    # the editability of various fields.
111
    if (defined $vars->{'default_state'}) {
112
	$vars->{'topic_readonly'} = 
113
	    Codestriker::topic_readonly($vars->{'default_state'});
114
    }
115
 
116
    my $query = new CGI;
117
    my $url_builder = Codestriker::Http::UrlBuilder->new($query);
118
 
119
    # Handle the links and parameters in the main title bar.
120
    $vars->{'list_url'} =
121
	$url_builder->list_topics_url("", "", "", "", "", "", "",
122
				      "", "", "", \@Codestriker::default_states_indexes, undef);
123
    $vars->{'create_topic_url'} = $url_builder->create_topic_url();
124
    $vars->{'search_url'} = $url_builder->search_url();
125
    $vars->{'doc_url'} = $url_builder->doc_url();
126
 
127
    my $data = "";
128
    my $rc = $self->{template}->process($self->{name} . ".html.tmpl",
129
					$vars, \$data);
130
    die $self->{template}->error() if (!defined $rc || $rc == 0);
131
    print $data;
132
    return $rc;
133
}
134
 
135
1;
136