« QBit/WebInterface/Controller/Form/Field/select.pm
↑ Summary
QBit/WebInterface/Controller/Form/Field/reCAPTCHA.pm »
| 1 | package QBit::WebInterface::Controller::Template::Provider; | ||
| 2 | $QBit::WebInterface::Controller::Template::Provider::VERSION = '0.033'; | ||
| 3 | use qbit; | ||
| 4 | |||
| 5 | use base qw(Template::Provider); | ||
| 6 | |||
| 7 | sub _minimize { | ||
| 8 | my ($self, $template) = @_; | ||
| 9 | |||
| 10 | # Remove TT2 comments | ||
| 11 | $template =~ s/\s*\[%#[^#]+#%\]\s*/ /go; | ||
| 12 | |||
| 13 | # Remove tail space | ||
| 14 | $template =~ s{\s+$}{}o; | ||
| 15 | $template =~ s{^\s+}{}o; | ||
| 16 | |||
| 17 | my @parts = split(/\s+/o, $template); | ||
| 18 | $template = $parts[0]; | ||
| 19 | my $r = $parts[0]; | ||
| 20 | |||
| 21 | for (my $i = 1; $i < scalar(@parts); $i++) { | ||
| 22 | unless ( | ||
| 23 | ($template =~ / $/o) | ||
| 24 | || ($parts[$i] =~ /^ /o) | ||
| 25 | || # Space already placed here | ||
| 26 | (($template =~ /<[^<>]+$/o) && ($parts[$i] =~ /^>/o)) | ||
| 27 | || # Tag closure | ||
| 28 | (($template =~ /%\]$/o) && ($parts[$i] =~ /^\[%/o)) | ||
| 29 | || # Between TT2 instructions | ||
| 30 | ($template =~ />$/o) || # After tag | ||
| 31 | ($parts[$i] =~ /^</o) || # Before tag | ||
| 32 | (($template =~ /%\]$/o) && ($template =~ />[^<]+$/o)) | ||
| 33 | || # After TT2 instruction outer of tags | ||
| 34 | (($parts[$i] =~ /^\[%/o) && ($template =~ />[^<]+$/o)) | ||
| 35 | || # Before TT2 instruction outer of tags | ||
| 36 | ( ($template =~ /<[^<>]+"$/o) | ||
| 37 | && (($parts[$i] =~ /^[^<>]*>/o) || ($parts[$i] !~ />/o))) # In a tag, space after " | ||
| 38 | ) | ||
| 39 | { | ||
| 40 | $parts[$i] = ' ' . $parts[$i]; | ||
| 41 | } | ||
| 42 | $template = substr $template, -100; | ||
| 43 | $template .= $parts[$i]; | ||
| 44 | $r .= $parts[$i]; | ||
| 45 | } | ||
| 46 | return $r; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub _load { | ||
| 50 | my $self = shift; | ||
| 51 | |||
| 52 | my ($data, $error) = $self->SUPER::_load(@_); | ||
| 53 | |||
| 54 | return ($data, $error) unless defined($data); | ||
| 55 | |||
| 56 | unless (utf8::is_utf8($data->{'text'})) { | ||
| 57 | utf8::decode($data->{'text'}); | ||
| 58 | } | ||
| 59 | |||
| 60 | $data->{'text'} = $self->_minimize($data->{'text'}) | ||
| 61 | if $self->{'PARAMS'}{'MINIMIZE'}; | ||
| 62 | |||
| 63 | return ($data, $error); | ||
| 64 | } | ||
| 65 | |||
| 66 | TRUE; |