--- trunk2/lib/WebPAC/Tree.pm 2004/10/19 16:30:12 529
+++ trunk2/lib/WebPAC/Tree.pm 2004/10/19 17:43:52 530
@@ -114,24 +114,10 @@
Create new tree object
my $tree = new WebPAC::Tree(
- dir => './out',
- html => 'browse.html',
- template => './output_template/tree.tt',
- js => 'tree-ids.js',
tree => \@tree,
log => 'log4perl.conf',
);
-C
is output directory in which html files and JavaScript files will be
-created (think of it as C).
-
-C is name of output html file.
-
-C is name of template. It uses Template Toolkit syntax [% var %],
-but doesn't really use TT.
-
-C is name of JavaScript file with shown and hidden ids.
-
C is tree array with levels of tree described above.
C is optional parametar which specify filename of L
@@ -149,23 +135,64 @@
my $log = $self->_get_logger();
- foreach my $p (qw(dir html template js tree)) {
- $log->logconfess("need $p") unless ($self->{$p});
- }
+ $log->logconfess("need tree") unless ($self->{'tree'});
$self->{'show_ids'} = [];
$self->{'hide_ids'} = [];
- my $html = $self->unroll(0,());
+ $self->{'tree_html'} = $self->unroll(0,());
- if (! $html) {
+ if (! $self->{'tree_html'}) {
$log->warn("no html generated by unroll...");
return;
}
- my $html_file = $self->{'dir'}.'/'.$self->{'html'};
+ return $self;
+}
+
+=head2 output
+
+Create output files from tree object
+
+ $tree->output(
+ dir => './out',
+ html => 'browse.html',
+ template => './output_template/tree.tt',
+ js => 'tree-ids.js',
+ );
+
+C is output directory in which html files and JavaScript files will be
+created (think of it as C).
+
+C is name of output html file.
+
+C is name of template. It uses Template Toolkit syntax [% var %],
+but doesn't really use TT.
+
+C is name of JavaScript file with shown and hidden ids.
+
+=cut
+
+sub output {
+ my $self = shift;
+
+ my $args = {@_};
+
+ my $log = $self->_get_logger();
+
+ foreach my $p (qw(dir html template js)) {
+ $log->logconfess("need $p") unless ($args->{$p});
+ }
+
+ my $html = $self->{'tree_html'};
+ unless ($html) {
+ $log->warn("no html, output aborted");
+ return;
+ }
+
+ my $html_file = $args->{'dir'}.'/'.$args->{'html'};
- open(TEMPLATE, $self->{'template'}) || $log->logdie("can't open '",$self->{'template'},": $!");
+ open(TEMPLATE, $args->{'template'}) || $log->logdie("can't open '",$args->{'template'},": $!");
my $tmpl;
while() {
$tmpl .= $_;
@@ -174,7 +201,7 @@
$log->info("creating '$html_file' with tree");
- my $js_arr_file = $self->{'js'};
+ my $js_arr_file = $args->{'js'};
$tmpl =~ s/\[%\s+js\s+%\]/$js_arr_file/gi;
$tmpl =~ s/\[%\s+tree\s+%\]/$html/gi;
@@ -182,7 +209,9 @@
print HTML $tmpl;
close(HTML);
- $self->generate_js();
+ $self->generate_js(
+ file => $args->{'dir'}."/".$args->{'js'},
+ );
return $self;
}
@@ -298,16 +327,21 @@
Generate JavaScript arrays C and C used to toggle display of
elements.
- $tree->generate_js();
+ $tree->generate_js(
+ file = "./out/tree-ids.js",
+ );
=cut
sub generate_js {
my $self = shift;
+ my $args = {@_};
+
my $log = $self->_get_logger();
- my $js_file = $self->{'dir'}.'/'.$self->{'js'};
+ my $js_file = $args->{'file'};
+ $log->die("need file") unless ($args->{'file'});
$log->info("creating '$js_file' with arrays of shown and hidden ids");