/[webpac2]/Webpacus/lib/Webpacus/Controller/Output.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/lib/Webpacus/Controller/Output.pm

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

trunk/lib/WebPAC/Output/TT.pm revision 280 by dpavlin, Sat Dec 17 22:32:28 2005 UTC Webpacus/lib/Webpacus/Controller/Output.pm revision 342 by dpavlin, Mon Jan 2 18:39:55 2006 UTC
# Line 8  use base qw/WebPAC::Common/; Line 8  use base qw/WebPAC::Common/;
8  use Template;  use Template;
9  use List::Util qw/first/;  use List::Util qw/first/;
10  use Data::Dumper;  use Data::Dumper;
11  use URI::Escape qw/uri_escape_utf8/;  use Encode;
12    
13  =head1 NAME  =head1 NAME
14    
# Line 16  WebPAC::Output::TT - use Template Toolki Line 16  WebPAC::Output::TT - use Template Toolki
16    
17  =head1 VERSION  =head1 VERSION
18    
19  Version 0.05  Version 0.06
20    
21  =cut  =cut
22    
23  our $VERSION = '0.05';  our $VERSION = '0.06';
24    
25  =head1 SYNOPSIS  =head1 SYNOPSIS
26    
# Line 145  C<d('FieldName','delimiter')>, where C<d Line 145  C<d('FieldName','delimiter')>, where C<d
145    
146  filter to return links to search, usage in TT:  filter to return links to search, usage in TT:
147    
148    [% search('FieldToDisplay','FieldToSearch','optional delimiter') %]    [% search('FieldToDisplay','FieldToSearch','optional delimiter', 'optional_template.tt') %]
149    
150  =cut  =cut
151    
# Line 157  filter to return links to search, usage Line 157  filter to return links to search, usage
157                                    
158                  return sub {                  return sub {
159    
160                          my ($display,$search,$delimiter) = @_;                          my ($display,$search,$delimiter,$template) = @_;
161                                                    
162                          # default delimiter                          # default delimiter
163                          $delimiter ||= '&#182;<br/>',                          $delimiter ||= '&#182;<br/>',
# Line 169  filter to return links to search, usage Line 169  filter to return links to search, usage
169                          my $item = $data->{'data'}->{$display} || return;                          my $item = $data->{'data'}->{$display} || return;
170    
171                          return unless($item->{'display'});                          return unless($item->{'display'});
172                          die "error in TT template: field $display didn't insert anything into search, use d('$display') and not search('$display'...)" unless($item->{'search'});                          if (! $item->{'search'}) {
173                                    warn "error in TT template: field $display didn't insert anything into search, use d('$display') and not search('$display'...)";
174                                    return;
175                            }
176    
177                          my @warn;                          my @warn;
178                          foreach my $type (qw/display search/) {                          foreach my $type (qw/display search/) {
# Line 198  filter to return links to search, usage Line 201  filter to return links to search, usage
201                                                  $s = $item->{'search'}->[0];                                                  $s = $item->{'search'}->[0];
202                                          }                                          }
203                                          #$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;                                          #$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
204                                          $s = uri_escape_utf8( $s );                                          $s = __quotemeta( $s );
205    
206                                          my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";                                          my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";
207    
208                                          push @html, <<__JS_LINK_SEARCH__                                          my $template_arg = '';
209  <a href="#" onclick="new WebPAC.Updater( 'results',  '/search/results?$search=$s', { asynchronous: 1,onLoading: function(request){show_searching();},onLoaded: function(request){hide_searching();} } ) ; return false">$d</a>                                          $template_arg = qq{,'$template'} if ($template);
210  __JS_LINK_SEARCH__  
211                                            push @html, qq{<a href="#" onclick="return search_via_link('$search','$s'${template_arg})">$d</a>};
212                                  }                                  }
213    
214                                  return join($delimiter, @html);                                  return join($delimiter, @html);
# Line 310  sub to_file { Line 314  sub to_file {
314  }  }
315    
316    
317    =head2 __quotemeta
318    
319    Helper to quote JavaScript-friendly characters
320    
321    =cut
322    
323    sub __quotemeta {
324            local $_ = shift;
325            $_ = decode('iso-8859-2', $_);
326    
327            s<([\x{0080}-\x{fffd}]+)>{sprintf '\u%0*v4X', '\u', $1}ge if ( Encode::is_utf8($_) );
328            {
329                    use bytes;  
330                    s<((?:[^ \x21-\x7E]|(?:\\(?!u)))+)>{sprintf '\x%0*v2X', '\x', $1}ge;
331            }
332    
333            s/\\x09/\\t/g;
334            s/\\x0A/\\n/g;
335            s/\\x0D/\\r/g;
336            s/"/\\"/g;
337            s/\\x5C/\\\\/g;
338    
339            return $_;
340    }
341    
342  =head1 AUTHOR  =head1 AUTHOR
343    
344  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.280  
changed lines
  Added in v.342

  ViewVC Help
Powered by ViewVC 1.1.26