Web::Chain project: Web/Pro/HtmlOutput.pm
package Web::Pro::HtmlOutput;
# doom@kzsu.stanford.edu
# 06 Oct 2004
=head1 NAME
Web::Pro::HtmlOutput - some procedural routines to output
doomfiles material in html form without using a templating system.
=head1 SYNOPSIS
use Web::Pro::HtmlOutput qw( header
footer
first_header
last_footer
text2html
);
See:
Web::Chain::IO::Output::Html
=head1 DESCRIPTION
Old-fashioned, proceedural code with embedded html
for handling the standard html formating of Web
material.
=head2 EXPORT
All of the following functions or OK for export:
=over
=cut
use 5.006;
use strict;
use warnings;
use Carp;
use POSIX qw(strftime);
use Web::Definitions qw( $DEBUG
$DF_VERSION
$DF_THOUGHTS_LINK_RULE
$DF_TOPNODE_NAME
$DF_WHATSNEW_NOW_MARKER
$DF_CONTENTS_NODE_NAME
);
use Web::Pro::Transform qw(
text2html
);
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw( header
footer
first_header
last_footer
text2html
add_node_list_to_whatsnew_body
nodelist_to_html
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw( );
our $VERSION = $DF_VERSION;
=item B<header> - generate the opening html header for a doomfiles page
Example usage:
print $fh header($node_name, $prev_node_name);
=cut
sub header {
my $node_name = shift;
my $prev_name = shift;
my $tagline = $_[0] || ""; # Not currently used
# (so shut up about the unit warnings)
my $top_node_name = $DF_TOPNODE_NAME; # Just 'TOP', really, defined in Web::Definitions
my $head = <<"HEADER";
<HTML><HEAD>
<TITLE>The doomfiles - $node_name.html</TITLE>
</HEAD><BODY>
<PRE> <A HREF="$prev_name.html">[PREV - $prev_name]</A> <A HREF="$top_node_name.html">[$top_node_name]</A></PRE>
<H1 align="left">$node_name</H1>
$tagline\n
<PRE>
HEADER
}
=item B<footer> - generate the closing html footer for a doomfiles page
Example usage:
print $fh footer($next_node_name);
=cut
sub footer {
my $next_name = shift;
my $tail = <<"TAIL";
--------
<A HREF="$next_name.html">[NEXT - $next_name]</A>
</PRE></BODY></HTML>
TAIL
}
=item B<first_header> - generate the opening html header for a doomfiles page
Example usage:
print $fh first_header($node_name);
=cut
sub first_header {
my $node_name = shift;
my $node = shift; # Not currently used.
my $top_node_name = $DF_TOPNODE_NAME; # Just 'TOP', really, defined in Web::Definitions
my $head = <<"HEADER";
<HTML><HEAD>
<TITLE>The doomfiles - $node_name.html</TITLE>
</HEAD><BODY>
<PRE> <A HREF="$top_node_name.html">[$top_node_name]</A></PRE>
<H1 align="left">$node_name</H1>
<PRE>
HEADER
}
=item B<last_footer> - generate the closing html footer for the last doomfiles page
in this chain.
Example usage:
print $fh last_footer(); # Need parens to keep from confusing perl (!!!)
=cut
sub last_footer {
my $node = shift; # Currently un-used
my $tail = <<"TAIL";
--------
</PRE></BODY></HTML>
TAIL
}
=item B<add_node_list_to_whatsnew_body> - Takes a reference to a list of
DF node names, inserts a list of links to them in the
contents (access is provided to this by a scaler string reference).
Based on the old doomtool-add_new_node_log_to_WHATSNEW script
Used on an interim basis by Web::Chain::IO::Html::log_new_nodes.
Example usage:
add_node_list_to_whatsnew_body($new_node_list_ref, $content_ref);
=cut
sub add_node_list_to_whatsnew_body {
my $new_node_list_ref = shift;
my $content_ref = shift;
my $subname = ( caller(0) )[3];
my $now_marker = $DF_WHATSNEW_NOW_MARKER;
my $datestamp = strftime("%D", localtime); # Jest call me uh 'merkin
($DEBUG) && print STDERR "datestamp: $datestamp\n";
${ $content_ref } =~ m{$now_marker}ms or die "$subname: Can't find $now_marker";
my $log_insert = define_log_insert($datestamp, $new_node_list_ref);
${ $content_ref } =~ s{
(
\Q$now_marker\E # The "NOW MARKER" phrase
\s* # Optional spaces
--> # Close of HTML comment surrounding now marker
) # end capture. Got prefix in $1 now.
}{$1$log_insert}xms ;
return $datestamp;
}
sub define_log_insert {
my $datestamp = shift;
my $new_node_list_ref = shift;
my $log_insert = "\n\n$datestamp\n\n";
$log_insert .= "Added:\n\n";
foreach my $name (@{ $new_node_list_ref }) {
$log_insert .= " <A HREF=\"$name.html\">$name</A>\n\n";
}
$log_insert .= "\n";
return $log_insert;
}
=item B<nodelist_to_html> -
Used by the *::Html::generate_contents_node method
to convert a listing (array reference) of node names into
a list of html links (text reference). Has one required
argument, a reference to an array of node names, and one
optional argument a prefix string that will be prepended
to each line (e.g. a string of spaces: ' ');
Loosely based on the old script: doomtool_generate_CONTENTS.
=cut
sub nodelist_to_html {
my $aref = shift;
my $prefix = shift;
$prefix = '' unless( $prefix );
my ($html_ref, $name);
foreach $name ( @{ $aref } ) {
${ $html_ref } .= "$prefix<A HREF=\"$name.html\">$name</A>\n"
unless ($name eq $DF_CONTENTS_NODE_NAME);
}
return $html_ref;
}
1;
__END__
=back
=head1 SEE ALSO
L<Project Documentation|Web::Project>
=head1 AUTHOR
Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2004 by Joseph Brenner
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.2 or,
at your option, any later version of Perl 5 you may have available.
=head1 BUGS
None reported... yet.
=cut
Joseph Brenner,
Sat Nov 6 17:04:11 2004