| … | |
… | |
| 17 | ($self->{r}, $self->{courseEnvironment}) = @_; |
17 | ($self->{r}, $self->{courseEnvironment}) = @_; |
| 18 | bless $self, $class; |
18 | bless $self, $class; |
| 19 | return $self; |
19 | return $self; |
| 20 | } |
20 | } |
| 21 | |
21 | |
| 22 | # Call this if you want the standard HTML headers, as specified in the |
|
|
| 23 | # template. A common call to this would be: |
|
|
| 24 | # $self->headers; return OK if $r->headers_only; |
|
|
| 25 | sub header { |
|
|
| 26 | my $self = shift; |
|
|
| 27 | my $r=$self->{r}; |
|
|
| 28 | $r->content_type('text/html'); |
|
|
| 29 | $r->send_http_header(); |
|
|
| 30 | } |
|
|
| 31 | |
22 | |
| 32 | # This generates the template code (eventually using a secondary storage |
23 | # This generates the template code (eventually using a secondary storage |
| 33 | # data source, I hope) for the common elements of all WeBWorK pages. |
24 | # data source, I hope) for the common elements of all WeBWorK pages. |
| 34 | # Arguments are substitutions for data points within the template. |
25 | # Arguments are substitutions for data points within the template. |
| 35 | sub top { |
26 | sub top { |
| … | |
… | |
| 86 | $html .= input({-type=>"hidden",-name=>"$param",-value=>"$value"}); |
77 | $html .= input({-type=>"hidden",-name=>"$param",-value=>"$value"}); |
| 87 | } |
78 | } |
| 88 | return $html; |
79 | return $html; |
| 89 | } |
80 | } |
| 90 | |
81 | |
| 91 | # Abstract as they get, this go() is meant to be over-ridden by |
82 | sub pre_header_initialize {} |
| 92 | # absolutely /anything/ that subclasses it. Most subclasses, however, |
|
|
| 93 | # will find it a useful thing to copy and modify, rather than writing from |
|
|
| 94 | # scratch. |
|
|
| 95 | |
83 | |
|
|
84 | sub header { |
|
|
85 | my $self = shift; |
|
|
86 | my $r=$self->{r}; |
|
|
87 | $r->content_type('text/html'); |
|
|
88 | $r->send_http_header(); |
|
|
89 | } |
|
|
90 | |
|
|
91 | sub initialize {} |
|
|
92 | |
|
|
93 | sub title { |
|
|
94 | print "Superclass"; |
|
|
95 | } |
|
|
96 | |
|
|
97 | sub body { |
|
|
98 | print "Generated content"; |
|
|
99 | } |
|
|
100 | |
| 96 | sub go() { |
101 | sub go { |
| 97 | my $self = shift; |
102 | my $self = shift; |
| 98 | my $r = $self->{r}; |
103 | my $r = $self->{r}; |
| 99 | my $courseEnvironment = $self->{courseEnvironment}; |
104 | my $courseEnvironment = $self->{courseEnvironment}; |
| 100 | |
105 | |
|
|
106 | $self->pre_header_initialize(@_); |
| 101 | $self->header; return OK if $r->header_only; |
107 | $self->header(@_); return OK if $r->header_only; |
|
|
108 | $self->initialize(@_); |
| 102 | |
109 | |
| 103 | print "You shouldn't see this. This is only a prototype."; |
110 | my $templateFile = $courseEnvironment->{templates}->{system}; |
|
|
111 | |
|
|
112 | open(TEMPLATE, $templateFile) or die "Couldn't open template $templateFile"; |
|
|
113 | my @template = <TEMPLATE>; |
|
|
114 | close TEMPLATE; |
|
|
115 | |
|
|
116 | foreach my $line (@template) { |
|
|
117 | my $pos = 0; |
|
|
118 | |
|
|
119 | while ($line =~ m/\G(.*?)<!--#(.*?)\s*-->/g) { |
|
|
120 | print "$1"; |
|
|
121 | $pos = pos($line); |
|
|
122 | print $self->$2(@_) if $self->can($2); |
|
|
123 | } |
|
|
124 | # I thought I could use pos($line) here, but /noooooo/ |
|
|
125 | print substr $line, $pos; |
|
|
126 | } |
|
|
127 | |
|
|
128 | return OK; |
| 104 | } |
129 | } |
| 105 | |
130 | |
| 106 | 1; |
131 | 1; |