--------------------- PatchSet 11421 Date: 2007/05/13 14:33:12 Author: adrian Branch: HEAD Tag: (none) Log: Begin writing pages. * flesh out a hacky template parser * try to massage the doc section into a sensible format. * build a very simple index page. Members: scripts/www/build-cfg-help.pl:1.5->1.6 scripts/www/template.html:INITIAL->1.1 Index: squid/scripts/www/build-cfg-help.pl =================================================================== RCS file: /cvsroot/squid/squid/scripts/www/build-cfg-help.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- squid/scripts/www/build-cfg-help.pl 13 May 2007 14:04:40 -0000 1.5 +++ squid/scripts/www/build-cfg-help.pl 13 May 2007 14:33:12 -0000 1.6 @@ -10,7 +10,7 @@ # # Adrian Chadd # -# $Id: build-cfg-help.pl,v 1.5 2007/05/13 14:04:40 adrian Exp $ +# $Id: build-cfg-help.pl,v 1.6 2007/05/13 14:33:12 adrian Exp $ # # The template file is reasonably simple to parse. There's a number of @@ -55,6 +55,13 @@ my (@names); my (%data); +# XXX should implement this! +sub uriescape($) +{ + my ($line) = @_; + return $line; +} + sub htmlescape($) { my ($line) = @_; @@ -66,20 +73,30 @@ GetOptions('verbose' => \$verbose, 'v' => \$verbose, 'out=s' => \$path); # -# Yes yes global variables suck. Rewrite it if you must. +# Yes, we could just read the template file in once..! # -sub generate_page($) +sub generate_page($$) { - my ($data) = @_; + my ($template, $data) = @_; # XXX should make sure the config option is a valid unix filename! my ($fn) = $path . "/" . $name . ".html"; my ($fh) = new IO::File; + my ($th) = new IO::File; $fh->open($fn, "w") || die "Couldn't open $fn: $!\n"; + $th->open($template, "r") || die "Couldn't open $template: $!\n"; - my ($ldoc) = $data->{"doc"}; - - print $ldoc; + # add in the local variables + $data->{"title"} = $data->{"name"}; + $data->{"ldoc"} = $data->{"doc"}; + $data->{"ldoc"} =~ s/\n\n/<\/p>\n

\n/; + # XXX and the end-of-line formatting to turn single \n's into
\n's. + + while (<$th>) { + # Do variable substitution + s/%(.*?)%/$data->{$1}/ge; + print $fh $_; + } close $fh; undef $fh; @@ -91,13 +108,11 @@ if ($_ =~ /^NAME: (.*)$/) { # If we have a name already; shuffle the data off and blank if (defined $name && $name ne "") { - generate_page(\%data); + generate_page("template.html", \%data); } undef %data; - $data{"nin"} = 0; - $data{"nocomment"} = []; - + $data{"doc"} = ""; my ($r) = {}; @{$r->{"aliases"}} = split(/ /, $1); $name = $r->{"name"} = $data{"name"} = $r->{"aliases"}[0]; @@ -125,14 +140,13 @@ } elsif ($_ =~ /^DEFAULT_IF_NONE: (.*)$/) { $data{"default_if_none"} = $1; } elsif ($_ =~ /^NOCOMMENT_END$/) { - $data{"nin"} ++; $state = ""; } elsif ($_ =~ /^IFDEF: (.*)$/) { $data{"ifdef"} = $1; } elsif ($state eq "doc") { $data{"doc"} .= $_ . "\n"; } elsif ($state eq "nocomment") { - $data{"nocomment"}->[$data{"nin"}] .= $_ . "\n"; + $data{"nocomment"} .= $_; } else { print "DEBUG: unknown line '$_'\n"; } @@ -140,18 +154,40 @@ # print last section if ($name ne "") { - generate_page(\%data); + generate_page("template.html", \%data); } # and now, the index file! -foreach (@names) -{ +my ($fh) = new IO::File; + +$fh->open($path . "/index.html", "w") || die "Couldn't open $path/index.html for writing: $!\n"; + +print $fh < + + Squid configuration file + + + +