Author: dylan
Date: 2005-03-14 23:51:14 -0500 (Mon, 14 Mar 2005)
New Revision: 646

Added:
   trunk/web/bin/
   trunk/web/bin/fixhtml
   trunk/web/bin/ttproc
   trunk/web/bin/validator.sh
Modified:
   trunk/
   trunk/web/Makefile
   trunk/web/templates/menu.tt
Log:
 [EMAIL PROTECTED]:  dylan | 2005-03-14 23:49:19 -0500
 build system works.



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:816
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
   + 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:817
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238

Modified: trunk/web/Makefile
===================================================================
--- trunk/web/Makefile  2005-03-15 04:51:13 UTC (rev 645)
+++ trunk/web/Makefile  2005-03-15 04:51:14 UTC (rev 646)
@@ -2,12 +2,11 @@
 
 # BEGIN CONFIG
 T         = templates
-DEPENDS  = $T/init $T/config bin/tt bin/fixhtml \
-                  $T/macros/html \
-                  $T/thanks \
-                  $T/sidebar \
-                  $T/menu \
-                  $T/page
+DEPENDS  = $T/config.tt bin/ttproc bin/fixhtml \
+                  $T/logos.tt \
+                  $T/sidebar.tt \
+                  $T/menu.tt \
+                  $T/page.tt
 
 # Extra build targets.
 TARGETS    = css/haver.css
@@ -74,7 +73,7 @@
        @echo "use make test from now on"
        
 
-
+%.html: templates/page.tt
 %.html: %.ttml
        @echo "TT   $<"
        @$(TT) $(TTFLAGS) $< > $@

Added: trunk/web/bin/fixhtml
===================================================================
--- trunk/web/bin/fixhtml       2005-03-15 04:51:13 UTC (rev 645)
+++ trunk/web/bin/fixhtml       2005-03-15 04:51:14 UTC (rev 646)
@@ -0,0 +1,195 @@
+#!/usr/bin/perl
+# FiXHTML.pl - does various things to XHTML files.
+# Copyright (C) 2003, 2004, 2005 Dylan William Hardison.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+use strict;
+use warnings;
+use File::Spec;
+use File::Basename;
+use Getopt::Long;
+use XML::DOM;
+use Image::Size;
+use Fatal qw(:void open close);
+Getopt::Long::Configure('gnu_getopt');
+
+my $parser = new XML::DOM::Parser;
+my %opt = (
+       verbose   => 0,
+    extension => 1,
+);
+
+GetOptions(\%opt,
+       'verbose|v+',
+    'extension|ext!',
+);
+
+my $doc;
+
+foreach my $file (@ARGV) {
+       die "$file is an absolute path!" if 
File::Spec->file_name_is_absolute($file);
+       
+       warn "Parsing $file.\n" if $opt{verbose} > 0;
+
+       my $in;
+       open $in, $file;
+       undef $/;
+       $_ = readline $in;
+       close $in;
+
+       if (s/<!--\s*?fix:\s*?(.+)\s*?:\s*?-->//) {
+               my %o = split(/\s*[,=]\s*/, $1);
+               foreach my $k (keys %o) {
+                       $opt{$k} = $o{$k};
+               }
+       }
+       s{//<!\[CDATA\[\n}{<!--\n}sg;
+       s{//\]\]>\n}{// -->}sg;
+       
+       $doc = $parser->parse($_);
+
+       warn "Fixing <a> tags.\n" if $opt{verbose} > 0;
+       foreach my $tag ($doc->getElementsByTagName('a', 1)) {
+               fix_href($tag, $file);
+       }
+       
+       warn "Fixing <link> tags.\n"  if $opt{verbose} > 0;
+       foreach my $tag ($doc->getElementsByTagName('link', 1)) {
+               fix_href($tag, $file);
+       }
+
+       warn "Fixing <img> tags.\n"  if $opt{verbose} > 0;
+       foreach my $tag ($doc->getElementsByTagName('img', 1)) {
+               fix_img($tag, $file);
+       }
+
+       warn "Fixing <script> tags.\n"  if $opt{verbose} > 0;
+       foreach my $tag ($doc->getElementsByTagName('script', 1)) {
+               fix_script($tag, $file);
+       }
+       
+       open my $fh, ">$file" or die "Can't open $file for writing: $!";
+       print $fh $doc->toString, "\n";
+       close $fh;
+
+    $doc->dispose;
+}
+
+
+sub fix_href {
+       my ($tag, $file) = @_;
+       
+       if (my $href = $tag->getAttribute('href')) {
+               my $new = rewrite_url($href, $file);
+        if ($new eq '.') {
+            $tag->setTagName('span');
+            $tag->setAttribute(class => 'nonlink');
+            $tag->removeAttribute('href');
+        } else {
+            $tag->setAttribute(href => $new);
+        }
+       }
+}
+
+sub fix_script {
+       my ($tag, $file) = @_;
+       
+       if (my $src = $tag->getAttribute('src')) {
+               $src = rewrite_url($src, $file);
+               $tag->setAttribute(src => $src);
+       }
+}
+
+sub fix_img {
+       my ($tag, $file) = @_;
+       
+       my ($width, $height) = ($tag->getAttribute('width'), 
$tag->getAttribute('height'));
+       my $src = $tag->getAttribute('src');
+       $tag->setAttribute(src => rewrite_url($src, $file));
+       
+       unless ($width and $height) {
+               my $imgfile = get_file_from_src($src, $file);
+               if ($imgfile) {
+                       my ($w,$h) = imgsize($imgfile);
+                       $tag->setAttribute(width  => $w);
+                       $tag->setAttribute(height => $h);
+               } else {
+            print STDERR "No image file named $src\n" if $opt{verbose};
+        }
+       }
+}
+sub rewrite_url {
+       my ($url, $file) = @_;
+    my ($dirs, $ret);
+    
+    return $url unless $url =~ m!^/!;
+    return $url if $url =~ /\?/;
+    
+    (undef, $dirs, undef) = File::Spec::Unix->splitpath($file);
+
+    if ($url eq "/$file") {
+        $ret = '.';
+    } else {
+        $ret = File::Spec::Unix->abs2rel($url, "/$dirs");
+    }
+    if (not $ret) {
+        $ret = 'index.html';
+    }
+    if (not $opt{ext}) {
+        $ret =~ s/\.\w+$//;
+    }
+   
+    if ($opt{verbose}) {
+        print STDERR "f('$url', '/$dirs') == '$ret'\n";
+    }
+
+
+
+    return $ret;
+}
+
+sub get_file_from_src {
+       my ($src, $page) = @_;
+       return undef if $src =~ m!^(https?|ftp|mailto|news):!;
+
+    my $file = do {
+        if ($src =~ m!^/!s) {
+            my $file = '.' . $src;
+            if (not -e $file) {
+                (glob("$file.*"))[0] || $file;
+            } else {
+                $file;
+            }
+        } else {
+            File::Spec->abs2rel(
+                File::Spec->catfile(dirname(File::Spec->rel2abs($page)), 
$src));
+        }
+    };
+    return $file;
+}
+
+
+BEGIN { 
+       XML::DOM::setTagCompression( sub {
+                       my ($tag, $elem) = @_;
+
+                       # Print empty br, hr and img tags like this: <br />
+                       return 2 if $tag =~ /^(br|hr|img|meta|link)$/;
+
+                       # Print other empty tags like this: <empty></empty>
+                       return 1;
+               }
+       );
+}


Property changes on: trunk/web/bin/fixhtml
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/web/bin/ttproc
===================================================================
--- trunk/web/bin/ttproc        2005-03-15 04:51:13 UTC (rev 645)
+++ trunk/web/bin/ttproc        2005-03-15 04:51:14 UTC (rev 646)
@@ -0,0 +1,81 @@
+#!/usr/bin/perl 
+
+# Copyright (C) 2004, 2005 Dylan Hardison
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+use strict;
+use warnings;
+use Template;
+use Getopt::Long 'GetOptions';
+
+my %opt = (
+       help           => 0,
+       define         => { },
+       'pre-process'  => [],
+       'include'      => ['.'],
+);
+
+Getopt::Long::Configure('gnu_getopt');
+GetOptions(\%opt,
+       'help|h',
+       'define|d|D=s',
+       'include|I=s@',
+       'pre-process|P=s@',
+);
+
+printhelp() if $opt{help};
+
+my $template = new Template(
+    {
+               ABSOLUTE => 1,
+               RELATIVE => 1,
+               INCLUDE_PATH => $opt{include},
+               PRE_PROCESS  => $opt{'pre-process'},
+               POST_CHOMP  => 1,
+               TRIM        => 1,
+               EVAL_PERL   => 1,
+               INTERPOLATE => 1,
+       },
+);
+
+my @files = @ARGV;
+
+unless (@files) {
+       push @files, '-';
+}
+foreach my $file (@files) {
+       if ($file eq '-') {
+               $file = \*STDIN;
+       }
+
+       $template->process($file, $opt{define})
+               or die $template->error(), "\n";
+}
+
+sub printhelp {
+    print <<HELP;
+Usage: ttproc [options] [files]
+    
+Options:
+  --help             (-h)    : display this message.
+  --define var=val   (-d,-D) : define template "var" to "value".
+  --include=path     (-I)    : append "path" to the TT include path.
+  --pre-process=file (-P)    : append "file" to the list of preprocessed files.
+HELP
+
+       exit 0;
+}


Property changes on: trunk/web/bin/ttproc
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/web/bin/validator.sh
===================================================================
--- trunk/web/bin/validator.sh  2005-03-15 04:51:13 UTC (rev 645)
+++ trunk/web/bin/validator.sh  2005-03-15 04:51:14 UTC (rev 646)
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Validate XHTML and XML files.
+# Copyright (C) 2005 Bryan Donlan
+# Modifications Copyright (C) 2005 Dylan Hardison
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+ALLOK=yes
+for file in "$@"; do
+       VALIDMARKER="$(dirname "$file")/.$(basename "$file" .html).valid"
+       if [ "$VALIDMARKER" -nt "$file" ]; then
+               continue
+       fi
+       
+       rm -f "$VALIDMARKER"
+       
+       printf "CHECK\t$file\n"
+       xmllint --valid --noout "$file"
+       RESULT=$?
+
+       if [ $RESULT == 0 ]; then
+               printf "OK\t$file\n"
+               touch "$VALIDMARKER"
+       else
+               ALLOK=no
+               printf "FAIL\t$file\n"
+       fi
+done
+
+if [ $ALLOK == yes ]; then
+       echo All files validated successfully.
+       exit 0
+else
+       echo One or more files failed to validate. See above messages.
+       exit 1
+fi


Property changes on: trunk/web/bin/validator.sh
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/web/templates/menu.tt
===================================================================
--- trunk/web/templates/menu.tt 2005-03-15 04:51:13 UTC (rev 645)
+++ trunk/web/templates/menu.tt 2005-03-15 04:51:14 UTC (rev 646)
@@ -1,24 +1,13 @@
-[%# vim: set ft=template: %]
-
-[%# vim: set ft=template: %]
-[% 
-
-# Main menu.
-menu = [
-       [ 'Home',     '/index.html'                                 ],
-       [ 'News',     'https://gna.org/news/index.php?group=haver'  ],
-       [ 'Wiki',     'http://wiki.chani3.com/wiki/ProjectHaver'    ],
-       [ 'Docs',     '/docs'                                       ],
-       [ 'Download', '/download.html'                              ],
-       [ 'Clients',  '/clients/index.html'                         ],
-       [ 'Contact',  '/contact.html'                               ],
-];
-
-FOREACH item IN menu;
-       link(item.1, item.0);
-       " - " UNLESS loop.last;
-END;
-
-
-%]
-
+<a href="/index.html">Home</a>
+ - 
+<a href="https://gna.org/news/index.php?group=haver";>News</a>
+ - 
+<a href="http://wiki.chani3.com/wiki/ProjectHaver";>Wiki</a>
+ - 
+<a href="/docs">Docs</a>
+ - 
+<a href="/download.html">Download</a>
+ - 
+<a href="/clients/index.html">Clients</a>
+ - 
+<a href="/contact.html">Contact</a>


Reply via email to