web site updates
[mono.git] / web / web / process.pl
1 #!/usr/bin/perl
2 #
3 # Author:
4 #   Sean MacIsaac
5 #
6
7 use strict;
8
9 my $full_expand = 1;
10 my @template;
11 my $n;
12
13 if ($#ARGV != 2) {
14   print "process.pl command_file template_file directory_prefix\n";
15   exit ();
16 }
17
18 my $menu = "";
19
20 open COMMANDS, $ARGV[0] || die "Can not open $ARGV[0]";
21 while (<COMMANDS>) {
22   chop;
23   my @command = split /,/;
24   if ($command[0] != -1) {
25       $menu .= "\t\t";
26           $menu .= "<tr><td valign=\"top\" class=\"navi" . $command[0];
27           $menu .= "\"><a class=\"navi" . $command[0];
28           $menu .= "\"";
29           $menu .= "HREF=\"$command[2]\">$command[1]</A></td></tr>\n\n";
30   } 
31 }
32 close COMMANDS;
33
34 open TEMPLATE, $ARGV[1] || die "Can not open $ARGV[1]";
35 while (<TEMPLATE>) {
36   push @template, $_;
37 }
38 close TEMPLATE;
39
40 open COMMANDS, $ARGV[0] || die "Can not open $ARGV[0]";
41 while (<COMMANDS>) {
42   chop;
43   my @command = split /,/;
44
45   if ($command[2] =~ /^http:/){
46   } else {
47           $n = $ARGV[2] . "/" . $command[2];
48           open OUTPUT, ">" . $n || die "Can not create $n";
49         
50           my $content = "";
51           open INPUT, "src/$command[3]" || die "Can not open $command[3]";
52           while (<INPUT>) {
53             $content .= $_;
54           }
55           close INPUT;
56         
57           my $line;
58           my $temp;
59           my $tit;
60           my $title;
61           my $css;
62           my $script;
63         
64           $tit = $command[1];
65           $css = $command[4];
66           $script = $command[5];
67
68           foreach $line (@template) {
69             $temp = $line;
70             $title = "$tit / Mono";
71             $temp =~ s/#TITLE#/$title/;
72             $temp =~ s/#CONTENT#/$content/;
73             $temp =~ s/#MENU#/$menu/;
74             if ($css) {
75               $temp =~ s/#CSS#/<LINK rel="stylesheet" type="text\/css" href="$css">/;
76             } else {
77               $temp =~ s/#CSS#//;
78             }
79                 
80             if ($script) {
81               $temp =~ s/#SCRIPT#/<SCRIPT src="$script"><\/SCRIPT>/;
82             } else {
83               $temp =~ s/#SCRIPT#//;
84             }
85             print OUTPUT $temp;
86           }
87  }      
88   close OUTPUT;
89 }