/[webpac2]/trunk/lib/WebPAC/Output/TT.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 /trunk/lib/WebPAC/Output/TT.pm

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

revision 42 by dpavlin, Mon Nov 14 16:11:40 2005 UTC revision 70 by dpavlin, Sat Nov 19 23:48:24 2005 UTC
# Line 70  Create output from in-memory data struct Line 70  Create output from in-memory data struct
70    
71   my $text = $tt->apply(   my $text = $tt->apply(
72          template => 'text.tt',          template => 'text.tt',
73          data => \@ds          data => $ds
74   );   );
75    
76    It also has follwing template toolikit filter routies defined:
77    
78  =cut  =cut
79    
80  sub apply {  sub apply {
# Line 86  sub apply { Line 88  sub apply {
88                  $log->logconfess("need $a") unless ($args->{$a});                  $log->logconfess("need $a") unless ($args->{$a});
89          }          }
90    
91          # filter to return value from @ds  =head3 tt_filter_type
   
         sub tt_filter_d {  
   
                 my ($name,$join) = @_;  
   
 print "### name = ",Dumper($name);  
92    
93                  my $item = first { $_->{'name'} eq $name } @{ $args->{'data'} };  filter to return values of specified from $ds
94    
95                  return unless($item);  =cut
   
 print "### item = ",Dumper($item);  
   
                 my $v = $item->{'display'} || return;  
96    
97                  if (ref($v) eq 'ARRAY') {          sub tt_filter_type {
98                          if ($#{$v} == 0) {                  my ($data,$type) = @_;
99                                  $v = $v->[0];                  
100                          } else {                  die "no data?" unless ($data);
101                                  $join = '&#182;<br/>' unless defined($join);                  $type ||= 'display';
102                                  $v = join($join, @{$v});  
103                    my $default_delimiter = {
104                            'display' => '&#182;<br/>',
105                            'index' => '\n',
106                    };
107    
108                    return sub {
109    
110                            my ($name,$join) = @_;
111    
112                            die "no data hash" unless ($data->{'data'} && ref($data->{'data'}) eq 'HASH');
113                            # Hm? Should we die here?
114                            return unless ($name);
115    
116                            my $item = $data->{'data'}->{$name} || return;
117    
118                            my $v = $item->{$type} || return;
119    
120                            if (ref($v) eq 'ARRAY') {
121                                    if ($#{$v} == 0) {
122                                            $v = $v->[0];
123                                    } else {
124                                            $join = $default_delimiter->{$type} unless defined($join);
125                                            $v = join($join, @{$v});
126                                    }
127                          }                          }
128    
129                            return $v;
130                  }                  }
 print "### v = $v\n";  
                 return $v;  
131          }          }
         $args->{'d'} = \&tt_filter_d;  
132    
133            $args->{'d'} = tt_filter_type($args, 'display');
134    
135          my $out;          my $out;
136    
# Line 135  to a file. Line 151  to a file.
151   $tt->to_file(   $tt->to_file(
152          file => 'out.txt',          file => 'out.txt',
153          template => 'text.tt',          template => 'text.tt',
154          data => \@ds          data => $ds
155   );   );
156    
157  =cut  =cut

Legend:
Removed from v.42  
changed lines
  Added in v.70

  ViewVC Help
Powered by ViewVC 1.1.26