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

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

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