Annotation of loncom/build/doc_template.pl, revision 1.10

1.8       harris41    1: # doc_template.pl - A perl script for beautifying doc/build/*.html files
1.1       harris41    2: 
1.8       harris41    3: # (Quick and dirty xml reading and substitution.)
                      4: 
1.1       harris41    5: 
                      6: # --------------------------------------- slurp in information
                      7: unless (scalar(@ARGV)==2) {
                      8:     die("invalid invocation of doc_template.pl");
                      9: }
                     10: my $template=shift @ARGV; my $data=shift @ARGV;
                     11: my @lines;
                     12: open IN,"<$data" or die("no file $data");
1.6       harris41   13: @lines=<IN>; close IN;
                     14: my $d=join('',@lines);
1.1       harris41   15: open IN,"<$template" or die("no file $data");
1.6       harris41   16: @lines=<IN>; close IN;
                     17: my $t=join('',@lines);
1.1       harris41   18: 
                     19: # ------- read in values from data
                     20: $d=~/\<title.*?\>(.*?)\<\/title.*?\>/s;
                     21: my $title=$1;
                     22: $t=~s/\<TITLE \/\>/$title/g;
                     23: $d=~/\$(.*?)\$/;
1.3       harris41   24: my $e=$1;
1.9       harris41   25: $e=~s/\S*\s\S*\s+\S*$/ last updated/;
1.7       harris41   26: my $cvsdate="<p align=\"left\"><font size=\"-2\"><i>CVS $e</i></font></p>";
1.1       harris41   27: $t=~s/\<DATE \/\>/$cvsdate/g;
                     28: $d=~/\<\!\-\- pdfahref (.*?) \-\-\>/;
                     29: my $pdfahref="<a href='$1'>";
                     30: $t=~s/\<PDFAHREF \/\>/$pdfahref/g;
                     31: 
                     32: my %bhash=(
                     33:     'CONFIGURE' => '/docs/reconfig/index.html',
                     34:     'INSTALL' => '/docs/install/index.html',
                     35:     'UPGRADE' => '/docs/upgrade/index.html',
                     36:     'FAQ' => '/docs/faq/index.html',
                     37:     'DOWNLOADS' => '/docs/downloads/index.html',
                     38:     'CONTACT' => '/docs/contact/index.html',
                     39:     'MAIN-SITE' => 'http://install.lon-capa.org',
1.2       harris41   40:     'LICENSE' => '/docs/license/index.html',
1.1       harris41   41: );
                     42: 
                     43: $d=~/\<\!\-\- button (.*?) \-\-\>/;
                     44: my $buttonv=$1;
                     45: while (1) {
                     46:     if ($t=~/\<BUTTON NAME=\'(.*?)\' \/\>/) {
                     47: 	my $bname=$1;
                     48: 	my $button;
                     49: 	my $bh=$bhash{$bname};
                     50: 	if ($buttonv eq $bname) {
                     51: 	    $button=<<END;
                     52: <table cellpadding='5' cellspacing='0' border='3'><tr><td>
                     53: <a href='$bh'>
                     54: <font face='helvetica'>
                     55: <font color='#009900'>
                     56: $bname
                     57: </font>
                     58: </font>
                     59: </a>
                     60: </td></tr></table>
                     61: END
                     62:         }
                     63: 	else {
                     64: 	    $button=<<END;
                     65: <table cellpadding='5' cellspacing='0' border='1'><tr><td>
                     66: <a href='$bh'>
                     67: <strong><font face='helvetica'>
                     68: <font color='#009900'>$bname</font>
                     69: </font></strong></a>
                     70: </td></tr></table>
                     71: END
                     72: 	}
                     73: 	$t=~s/\<BUTTON NAME=\'$bname\' \/\>/$button/g;
                     74:     }
                     75:     else {
                     76: 	last;
                     77:     }
                     78: }
                     79: $d=~/\<\!\-\- preamble start \-\-\>(.*?)\<\!\-\- preamble end \-\-\>/s;
                     80: my $preamble=$1;
1.6       harris41   81: $preamble=~s/\<p([^\>]*)\>/<p$1><font face="helvetica">/g;
                     82: $preamble=~s/\<\/p([^\>]*)\>/<\/font><\/p$1>/g;
                     83: $preamble=~s/\<li([^\>]*)\>/<li$1><font face="helvetica">/g;
                     84: $preamble=~s/\<\/li([^\>]*)\>/<\/font><\/li$1>/g;
1.1       harris41   85: $t=~s/\<PREAMBLE \/\>/$preamble/g;
                     86: $d=~/\<\!\-\- maintext start \-\-\>(.*?)\<\!\-\- maintext end \-\-\>/s;
                     87: my $maintext=$1;
                     88: $t=~s/\<MAINTEXT \/\>/$maintext/g;
1.6       harris41   89: my $v=(<<END);
1.7       harris41   90: <p align="right">
1.6       harris41   91:  <a href="http://validator.w3.org/check/referer"><img
1.7       harris41   92:         src="/loncapa_doc_icons/valid-xhtml10"
1.6       harris41   93:         alt="Valid XHTML 1.0!" height="31" width="88" /></a>
                     94: </p>
                     95: END
                     96: if ($d=~/\<\!\-\- validated \-\-\>/) {
                     97:     $t=~s/\<VALIDATED \/\>/$v/g;
                     98: }
                     99: else {
                    100:     $t=~s/\<VALIDATED \/\>//g;
                    101: }
1.1       harris41  102: print $t;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>