Subversion Repositories DevTools

Rev

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