--- trunk2/lib/WebPAC/Tree.pm 2004/11/01 14:55:16 572 +++ trunk2/lib/WebPAC/Tree.pm 2004/11/06 18:36:54 584 @@ -128,6 +128,12 @@ my $tree = new WebPAC::Tree( tree => \@tree, log => 'log4perl.conf', + detail_url => sub { + my $mfn = shift; + my $path = "thes/${mfn}.html"; + return $path if (-e "./out/$path"); + }, + nodes_dir => 'nodes', ); C is tree array with levels of tree described above. @@ -135,6 +141,12 @@ C is optional parametar which specify filename of L config file. Default is C. +C code ref to check if detail html exists (and return URL if +it does). + +C is relative path from output directory where tree nodes for +iframes will be created. + =cut sub new { @@ -152,6 +164,15 @@ $self->{'show_ids'} = []; $self->{'hide_ids'} = []; + # figure out relative URL to other content from nodes_dir + my $iframe_base = $self->{'nodes_dir'}; + if ($iframe_base) { + $iframe_base = s#[^/]*##g; + $iframe_base = '../' x ( length($iframe_base) ); + $self->{'iframe_base'} = $iframe_base; + $log->debug("nodes dir is '",$self->{'nodes_dir'},"' so iframe_base is '",$self->{'iframe_base'},"'"); + } + $self->{'tree_html'} = $self->unroll(0,()); if (! $self->{'tree_html'}) { @@ -231,14 +252,14 @@ file => $js_file, ); - if (! $args->{'nodes'}) { + if (! $self->{'nodes_dir'}) { $log->warn("skipping node creation"); return $self; } foreach my $mfn (keys %{$self->{'node_html'}}) { - my $html_file = $args->{'dir'}."/".$args->{'nodes'}."/${mfn}.html"; + my $html_file = $args->{'dir'}."/".$self->{'nodes_dir'}."/${mfn}.html"; $log->debug("creating tree node $html_file"); @@ -263,7 +284,9 @@ sub unroll { my $self = shift; - my ($level,$data_arr) = @_; + my ($level,$data_arr, $base_path) = @_; + + $base_path ||= ''; my $log = $self->_get_logger(); @@ -284,7 +307,7 @@ # all levels passed? return if (! defined($tree->[$level])); - $log->debug("unroll level $level"); + $log->debug("unroll level $level base path ",($base_path || "none")); my $html; @@ -305,7 +328,7 @@ $log->debug("$code -> $v900 : $term [$mfn]"); - my ($link_start,$link_end) = ('',''); + my ($link_start,$link_end,$level_el) = ('','','ul'); my $have_children = $tree->[$level]->{'have_children'}->($code,$v900); @@ -316,26 +339,42 @@ } - ($link_start,$link_end) = (qq{},qq{}) if ($have_children); + my $iframe = $tree->[$level]->{'iframe'}; - my $mfn_link = "thes/$mfn.html"; - if (-e "out/$mfn_link") { - $term =~ s# *\* *# #; + if ($have_children) { + ($link_start,$link_end) = (qq{},qq{}); + if ($iframe) { + my $url = $self->{'nodes_dir'} || $log->logdie("no nodes_dir?"); + $url .= "/${mfn}.html"; + $link_start = qq{}; + $level_el = 'div'; + } + } + + my $mfn_link; + $mfn_link = $self->{'detail_url'}->($mfn) if ($self->{'detail_url'}); + + if ($mfn_link) { + $term =~ s/ *#C# */ /; $html .= " " x $level . qq{
  • ${link_start}${term}${link_end}}. - qq{ 
  • \n}; + qq{ \n}; + $log->debug("linked details to $mfn_link"); } else { $log->warn("file 'out/$mfn_link' doesn't exist, skipping"); } + # save mfn for iframe + push @{$self->{'mfn_arr'}}, $mfn; + unless ($have_children) { next; } my $style = $tree->[$level]->{'style'}; $html .= " " x $level . - qq{
      \n}; if ($style) { @@ -349,16 +388,26 @@ push @{$self->{'show_ids'}}, "id$mfn"; } - if ($tree->[$level]->{'iframe'}) { + + if ($iframe) { + + # reset list of current mfns + $self->{'mfn_arr'} = (); + # unroll to separate file - $self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children); + $self->{'node_html'}->{$mfn} = $self->unroll($next_level, $have_children, $self->{'iframe_base'}); + $html .= " " x $level . qq{\n}; + + $html .= " " x $level . + qq{\n}; + @{$self->{'iframe_mfn'}->{$mfn}} = @{$self->{'mfn_arr'}}; } else { # unroll at base HTML - $html .= $self->unroll($next_level, $have_children); + $html .= $self->unroll($next_level, $have_children, $base_path); } - $html .= " " x $level . qq{
    \n}; + $html .= " " x $level . qq{\n}; } } @@ -391,6 +440,15 @@ open(JS, ">", $js_file) || $log->logdie("can't open '$js_file': $!"); print JS "var show = ['",join("','",@{$self->{'show_ids'}}),"'];\n"; print JS "var hide = ['",join("','",@{$self->{'hide_ids'}}),"'];\n"; + + my @mfn_iframe; + + foreach my $if (keys %{$self->{'iframe_mfn'}}) { + push @mfn_iframe, join(",", map { "$_:$if" } @{$self->{'iframe_mfn'}->{$if}}); + } + + print JS "var mfn_iframe = {\n",join(",\n",@mfn_iframe),"\n};\n"; + close(JS); $log->debug("stored ",scalar @{$self->{'show_ids'}}," shown and ",scalar @{$self->{'hide_ids'}}," hidden elements");