/[webpac]/trunk2/lib/WebPAC/Tree.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 /trunk2/lib/WebPAC/Tree.pm

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

revision 574 by dpavlin, Mon Nov 1 17:19:48 2004 UTC revision 575 by dpavlin, Mon Nov 1 18:00:26 2004 UTC
# Line 133  Create new tree object Line 133  Create new tree object
133                  my $path = "thes/${mfn}.html";                  my $path = "thes/${mfn}.html";
134                  return $path if (-e "./out/$path");                  return $path if (-e "./out/$path");
135          },          },
136          iframe_base => '../',          nodes_dir => 'nodes',
137   );   );
138    
139  C<tree> is tree array with levels of tree described above.  C<tree> is tree array with levels of tree described above.
# Line 144  config file. Default is C<log.conf>. Line 144  config file. Default is C<log.conf>.
144  C<detail_url> code ref to check if detail html exists (and return URL if  C<detail_url> code ref to check if detail html exists (and return URL if
145  it does).  it does).
146    
147  C<iframe_base> is relative path from C<dir> defiend in C<output> to root  C<nodes_dir> is relative path from output directory where tree nodes for
148  (which is inserted in all html).  iframes will be created.
149    
150  =cut  =cut
151    
# Line 164  sub new { Line 164  sub new {
164          $self->{'show_ids'} = [];          $self->{'show_ids'} = [];
165          $self->{'hide_ids'} = [];          $self->{'hide_ids'} = [];
166    
167            # figure out relative URL to other content from nodes_dir
168            my $iframe_base = $self->{'nodes_dir'};
169            if ($iframe_base) {
170                    $iframe_base = s#[^/]*##g;
171                    $iframe_base = '../' x ( length($iframe_base) );
172                    $self->{'iframe_base'} = $iframe_base;
173                    $log->debug("nodes dir is '",$self->{'nodes_dir'},"' so iframe_base is '",$self->{'iframe_base'},"'");
174            }
175    
176          $self->{'tree_html'} = $self->unroll(0,());          $self->{'tree_html'} = $self->unroll(0,());
177    
178          if (! $self->{'tree_html'}) {          if (! $self->{'tree_html'}) {
# Line 184  Create output files from tree object Line 193  Create output files from tree object
193          template_dir => './output_template/',          template_dir => './output_template/',
194          template_tree => 'tree.tt',          template_tree => 'tree.tt',
195          template_node => 'node.tt',          template_node => 'node.tt',
         nodes => 'nodes',  
196          js => 'tree-ids.js',          js => 'tree-ids.js',
197   );   );
198    
# Line 200  C<template_tree> is name of template to Line 208  C<template_tree> is name of template to
208  C<template_node> is (optional) name of template for node (if C<iframe>  C<template_node> is (optional) name of template for node (if C<iframe>
209  options is used within tree definition).  options is used within tree definition).
210    
 C<nodes> is directory in C<dir> in which html for iframes will be located.  
 See also C<iframe_base> for relative dir out of this directory.  
   
211  C<js> is name of JavaScript file with shown and hidden ids.  C<js> is name of JavaScript file with shown and hidden ids.
212    
213  =cut  =cut
# Line 247  sub output { Line 252  sub output {
252                  file => $js_file,                  file => $js_file,
253          );          );
254    
255          if (! $args->{'nodes'}) {          if (! $self->{'nodes_dir'}) {
256                  $log->warn("skipping node creation");                  $log->warn("skipping node creation");
257                  return $self;                  return $self;
258          }          }
259    
260          foreach my $mfn (keys %{$self->{'node_html'}}) {          foreach my $mfn (keys %{$self->{'node_html'}}) {
261    
262                  my $html_file = $args->{'dir'}."/".$args->{'nodes'}."/${mfn}.html";                  my $html_file = $args->{'dir'}."/".$self->{'nodes_dir'}."/${mfn}.html";
263    
264                  $log->debug("creating tree node $html_file");                  $log->debug("creating tree node $html_file");
265    
# Line 302  sub unroll { Line 307  sub unroll {
307          # all levels passed?          # all levels passed?
308          return if (! defined($tree->[$level]));          return if (! defined($tree->[$level]));
309    
310          $log->debug("unroll level $level");          $log->debug("unroll level $level base path ",($base_path || "none"));
311    
312          my $html;          my $html;
313    
# Line 334  sub unroll { Line 339  sub unroll {
339    
340                          }                          }
341    
342                          ($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>}) if ($have_children);                          my $iframe = $tree->[$level]->{'iframe'};
343    
344                            if ($have_children) {
345                                    ($link_start,$link_end) = (qq{<a href="#mfn$mfn" onClick="return toggle_display('id$mfn');">},qq{</a>});
346                                    if ($iframe) {
347                                            my $url = $self->{'nodes_dir'} || $log->logdie("no nodes_dir?");
348                                            $url .= "/${mfn}.html";
349                                            $link_start = qq{<a href="#mfn$mfn" onClick="iframe_load('i$mfn','$url'); return toggle_display('id$mfn');">};
350                                    }
351                            }
352    
353                          my $mfn_link;                          my $mfn_link;
354                          $mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'});                          $mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'});
# Line 374  sub unroll { Line 388  sub unroll {
388                          }                          }
389    
390    
391                          if ($tree->[$level]->{'iframe'}) {                          if ($iframe) {
392    
393                                  # reset list of current mfns                                  # reset list of current mfns
394                                  $self->{'mfn_arr'} = ();                                  $self->{'mfn_arr'} = ();
# Line 382  sub unroll { Line 396  sub unroll {
396                                  # unroll to separate file                                  # unroll to separate file
397                                  $self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, $self->{'iframe_base'});                                  $self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, $self->{'iframe_base'});
398                                  $html .= " " x $level .                                  $html .= " " x $level .
399                                  qq{<iframe id="i$mfn" name="i$mfn" width="100%" height="10" frameborder="0" border="0"></iframe>};                                  qq{<iframe id="i$mfn" name="i$mfn" width="100%" height="0" frameborder="0" border="0" onLoad="iframe_resize(this.name);"></iframe>};
400                                  @{$self->{'iframe_mfn'}->{$mfn}} = @{$self->{'mfn_arr'}};                                  @{$self->{'iframe_mfn'}->{$mfn}} = @{$self->{'mfn_arr'}};
                                 $log->debug("in this iframe: ", sub { Dump($self->{'iframe_mfn'}->{$mfn}) });  
401    
402                          } else {                          } else {
403                                  # unroll at base HTML                                  # unroll at base HTML
# Line 427  sub generate_js { Line 440  sub generate_js {
440    
441          print JS "var mfn_iframe = [\n";          print JS "var mfn_iframe = [\n";
442          foreach my $if (keys %{$self->{'iframe_mfn'}}) {          foreach my $if (keys %{$self->{'iframe_mfn'}}) {
443                  print JS " ",join(",",map { "[$_:$if]" } @{$self->{'iframe_mfn'}->{$if}}),",\n";  #               print JS " ",join(",",map { "[$_:$if]" } @{$self->{'iframe_mfn'}->{$if}}),",\n";
444          }          }
445          print JS " null\n]\n";          print JS " null\n]\n";
446    

Legend:
Removed from v.574  
changed lines
  Added in v.575

  ViewVC Help
Powered by ViewVC 1.1.26