|
Lines 2-10
package TmplTokenizer;
Link Here
|
| 2 |
|
2 |
|
| 3 |
use strict; |
3 |
use strict; |
| 4 |
#use warnings; FIXME - Bug 2505 |
4 |
#use warnings; FIXME - Bug 2505 |
| 5 |
use TmplTokenType; |
5 |
use C4::TmplTokenType; |
| 6 |
use TmplToken; |
6 |
use C4::TmplToken; |
| 7 |
use TTParser; |
7 |
use C4::TTParser; |
| 8 |
use VerboseWarnings qw( pedantic_p error_normal warn_normal warn_pedantic ); |
8 |
use VerboseWarnings qw( pedantic_p error_normal warn_normal warn_pedantic ); |
| 9 |
require Exporter; |
9 |
require Exporter; |
| 10 |
|
10 |
|
|
Lines 68-74
sub new {
Link Here
|
| 68 |
shift; |
68 |
shift; |
| 69 |
my ($filename) = @_; |
69 |
my ($filename) = @_; |
| 70 |
#open my $handle,$filename or die "can't open $filename"; |
70 |
#open my $handle,$filename or die "can't open $filename"; |
| 71 |
my $parser = TTParser->new; |
71 |
my $parser = C4::TTParser->new; |
| 72 |
$parser->build_tokens( $filename ); |
72 |
$parser->build_tokens( $filename ); |
| 73 |
bless { |
73 |
bless { |
| 74 |
filename => $filename, |
74 |
filename => $filename, |
|
Lines 259-269
sub _formalize_string_cformat{
Link Here
|
| 259 |
|
259 |
|
| 260 |
sub _formalize{ |
260 |
sub _formalize{ |
| 261 |
my $t = shift; |
261 |
my $t = shift; |
| 262 |
if( $t->type == TmplTokenType::DIRECTIVE ){ |
262 |
if( $t->type == C4::TmplTokenType::DIRECTIVE ){ |
| 263 |
return '%s'; |
263 |
return '%s'; |
| 264 |
} elsif( $t->type == TmplTokenType::TEXT ){ |
264 |
} elsif( $t->type == C4::TmplTokenType::TEXT ){ |
| 265 |
return _formalize_string_cformat( $t->string ); |
265 |
return _formalize_string_cformat( $t->string ); |
| 266 |
} elsif( $t->type == TmplTokenType::TAG ){ |
266 |
} elsif( $t->type == C4::TmplTokenType::TAG ){ |
| 267 |
if( $t->string =~ m/^a\b/is ){ |
267 |
if( $t->string =~ m/^a\b/is ){ |
| 268 |
return '<a>'; |
268 |
return '<a>'; |
| 269 |
} elsif( $t->string =~ m/^input\b/is ){ |
269 |
} elsif( $t->string =~ m/^input\b/is ){ |
|
Lines 281-293
sub _formalize{
Link Here
|
| 281 |
} |
281 |
} |
| 282 |
|
282 |
|
| 283 |
# internal parametization, used within next_token |
283 |
# internal parametization, used within next_token |
| 284 |
# method that takes in an array of TEXT and DIRECTIVE tokens (DIRECTIVEs must be GET) and return a TmplTokenType::TEXT_PARAMETRIZED |
284 |
# method that takes in an array of TEXT and DIRECTIVE tokens (DIRECTIVEs must be GET) and return a C4::TmplTokenType::TEXT_PARAMETRIZED |
| 285 |
sub _parametrize_internal{ |
285 |
sub _parametrize_internal{ |
| 286 |
my $this = shift; |
286 |
my $this = shift; |
| 287 |
my @parts = @_; |
287 |
my @parts = @_; |
| 288 |
# my $s = ""; |
288 |
# my $s = ""; |
| 289 |
# for my $item (@parts){ |
289 |
# for my $item (@parts){ |
| 290 |
# if( $item->type == TmplTokenType::TEXT ){ |
290 |
# if( $item->type == C4::TmplTokenType::TEXT ){ |
| 291 |
# $s .= $item->string; |
291 |
# $s .= $item->string; |
| 292 |
# } else { |
292 |
# } else { |
| 293 |
# #must be a variable directive |
293 |
# #must be a variable directive |
|
Lines 297-303
sub _parametrize_internal{
Link Here
|
| 297 |
my $s = join( "", map { _formalize $_ } @parts ); |
297 |
my $s = join( "", map { _formalize $_ } @parts ); |
| 298 |
# should both the string and form be $s? maybe only the later? posibly the former.... |
298 |
# should both the string and form be $s? maybe only the later? posibly the former.... |
| 299 |
# used line number from first token, should suffice |
299 |
# used line number from first token, should suffice |
| 300 |
my $t = TmplToken->new( $s, TmplTokenType::TEXT_PARAMETRIZED, $parts[0]->line_number, $this->filename ); |
300 |
my $t = C4::TmplToken->new( $s, C4::TmplTokenType::TEXT_PARAMETRIZED, $parts[0]->line_number, $this->filename ); |
| 301 |
$t->set_children(@parts); |
301 |
$t->set_children(@parts); |
| 302 |
$t->set_form($s); |
302 |
$t->set_form($s); |
| 303 |
return $t; |
303 |
return $t; |
|
Lines 321-334
sub next_token {
Link Here
|
| 321 |
} |
321 |
} |
| 322 |
# if cformat mode is off, dont bother parametrizing, just return them as they come |
322 |
# if cformat mode is off, dont bother parametrizing, just return them as they come |
| 323 |
return $next unless $self->allow_cformat_p; |
323 |
return $next unless $self->allow_cformat_p; |
| 324 |
if( $next->type == TmplTokenType::TEXT ){ |
324 |
if( $next->type == C4::TmplTokenType::TEXT ){ |
| 325 |
push @parts, $next; |
325 |
push @parts, $next; |
| 326 |
} |
326 |
} |
| 327 |
# elsif( $next->type == TmplTokenType::DIRECTIVE && $next->string =~ m/\[%\s*\w+\s*%\]/ ){ |
327 |
# elsif( $next->type == C4::TmplTokenType::DIRECTIVE && $next->string =~ m/\[%\s*\w+\s*%\]/ ){ |
| 328 |
elsif( $next->type == TmplTokenType::DIRECTIVE ){ |
328 |
elsif( $next->type == C4::TmplTokenType::DIRECTIVE ){ |
| 329 |
push @parts, $next; |
329 |
push @parts, $next; |
| 330 |
} |
330 |
} |
| 331 |
elsif ( $next->type == TmplTokenType::CDATA){ |
331 |
elsif ( $next->type == C4::TmplTokenType::CDATA){ |
| 332 |
$self->_set_js_mode(1); |
332 |
$self->_set_js_mode(1); |
| 333 |
my $s0 = $next->string; |
333 |
my $s0 = $next->string; |
| 334 |
my @head = (); |
334 |
my @head = (); |
|
Lines 383-389
sub parametrize ($$$$) {
Link Here
|
| 383 |
my $param = $params[$i - 1]; |
383 |
my $param = $params[$i - 1]; |
| 384 |
warn_normal "$fmt_0: $&: Expected a TMPL_VAR, but found a " |
384 |
warn_normal "$fmt_0: $&: Expected a TMPL_VAR, but found a " |
| 385 |
. $param->type->to_string . "\n", undef |
385 |
. $param->type->to_string . "\n", undef |
| 386 |
if $param->type != TmplTokenType::DIRECTIVE; |
386 |
if $param->type != C4::TmplTokenType::DIRECTIVE; |
| 387 |
warn_normal "$fmt_0: $&: Unsupported " |
387 |
warn_normal "$fmt_0: $&: Unsupported " |
| 388 |
. "field width or precision\n", undef |
388 |
. "field width or precision\n", undef |
| 389 |
if defined $width || defined $prec; |
389 |
if defined $width || defined $prec; |
|
Lines 400-406
sub parametrize ($$$$) {
Link Here
|
| 400 |
if (!defined $param) { |
400 |
if (!defined $param) { |
| 401 |
warn_normal "$fmt_0: $&: Parameter $i not known", undef; |
401 |
warn_normal "$fmt_0: $&: Parameter $i not known", undef; |
| 402 |
} else { |
402 |
} else { |
| 403 |
if ($param->type == TmplTokenType::TAG |
403 |
if ($param->type == C4::TmplTokenType::TAG |
| 404 |
&& $param->string =~ /^<input\b/is) { |
404 |
&& $param->string =~ /^<input\b/is) { |
| 405 |
my $type = defined $param->attributes? |
405 |
my $type = defined $param->attributes? |
| 406 |
lc($param->attributes->{'type'}->[1]): undef; |
406 |
lc($param->attributes->{'type'}->[1]): undef; |