#use wml::fmt::sdf
#use wml::std::grid

<:

sub get_wml_subject {
  my ($file) = @_;
  open(FILE,$file);
  my $subject = <FILE>;
  close(FILE);
  return undef if ($subject !~ /.*<\s*subject\s*(.*)\s*>.*/);
  $subject =~ s/.*<\s*subject\s*(.*)\s*>.*/$1/;
  $subject =~ s/^"(.*)"$/$1/;
  $subject =~ s/^'(.*)'$/$1/;
  return $subject;
}

sub add_wml_menu_entry {
  my ($dir,$style,$order) = @_;
  my $file ="$dir/index.wml";
  my $subj = get_wml_subject($file);
  if (defined $subj)
  {
    if ($order)
    {
      print "<li class=\"$style\"><a href=\"$dir/index.html\">$subj</a></li>\n";
    }
    else
    {
      print "<a href=\"$dir/index.html\"><li class=\"$style\">$subj</li></a>\n";
    }
  }
}

sub get_wml_subdirectories {
  my ($dir) = @_;
  opendir(DIR,$dir);
  my (@dir) = grep(!/^\./ && -d "$dir/$_" && !/CVS/ && ! -l "$dir/$_", readdir(DIR));
  closedir(DIR);
  return @dir;
}

:>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>{#SUBJECT_LOC#}</title>
    <link rel=StyleSheet href="<get-var ROOT>/main.css" type="text/css">
    {#HEADER#}
  </head>
  
  <body>
    <div class="header">
      <grid layout=2x1 valign=c spacing=20px>
      <cell>
        <img src="<get-var ROOT>/blaise-header.jpg" alt="A picture of Blaise Gassend">
      </cell>
      <cell>
        <div class="titleline">{#SUBJECT_LOC#}</div>
	<div align="right" class="byblaisegassend">by <a
	href="mailto:blaise@gassend.com">Blaise Gassend</a></div>
      </cell>
      </grid>
    </div>
    <div class="menu"><ul>

    <: 
    {
      my $entry = "<get-var ROOT>";
      while ($entry =~ /\.\./) {
        $break++;
        add_wml_menu_entry($entry, "parentmenuentry", 0);
        if ($entry eq "..") {
	  $entry = "."
	}
	else { 
	  $entry =~ s/\.\.\///
	}
      }

      add_wml_menu_entry($entry, "currentmenuentry", 0);
      
      my @children = get_wml_subdirectories(".");
      foreach my $ndir (@children)
      {
        add_wml_menu_entry("$ndir", "childmenuentry", 0);
      }
    }

    :>

    </ul></div>
    <div align="justify" class="mainbody">
      {#BODY#}
    </div>
    <div align="justify" class="footer">
      <grid layout=2x1 align=lr valign=c width="100%">
      <cell>
      {#FOOTER#}
      
      This page was generated by the <a href="http://thewml.org/">Website META Language</a>
      by Ralf S. Engelschall from <a href="<:=$SRCFILE:>" TYPE="text/plain"> this source.</a>
     
      <br>&#169; 2003-2004 <a href="mailto:blaise@gassend.com">Blaise Gassend</a>. 
      All rights reserved.
      </cell>
      <cell>
        {#NEDSTAT#}
      </cell>
      </grid>
    </div>
    <script src="http://www.google-analytics.com/urchin.js"
    type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "UA-2660128-1";
    urchinTracker();
    </script>
  </body>
</html>

<define-tag subject>
{#SUBJECT_LOC#:%0:##}
</define-tag>

{#BODY#:

