[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/ContentGenerator.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 348 Revision 349
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;
25sub 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.
35sub top { 26sub 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 82sub 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
84sub header {
85 my $self = shift;
86 my $r=$self->{r};
87 $r->content_type('text/html');
88 $r->send_http_header();
89}
90
91sub initialize {}
92
93sub title {
94 print "Superclass";
95}
96
97sub body {
98 print "Generated content";
99}
100
96sub go() { 101sub 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
1061; 1311;

Legend:
Removed from v.348  
changed lines
  Added in v.349

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9