- Added some stuff to MANIFEST.SKIP
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / HTML.pm
index 8d91bff..87c399d 100644 (file)
@@ -1,10 +1,9 @@
 package SQL::Translator::Producer::HTML;
 
 # -------------------------------------------------------------------
-# $Id: HTML.pm,v 1.10 2003-10-17 19:51:57 dlc Exp $
+# $Id$
 # -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-#                    darren chamberlain <darren@cpan.org>
+# Copyright (C) 2002-4 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -25,7 +24,7 @@ use strict;
 use Data::Dumper;
 use vars qw($VERSION $NOWRAP $NOLINKTABLE $NAME);
 
-$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/;
 $NAME = join ', ', __PACKAGE__, $VERSION;
 $NOWRAP = 0 unless defined $NOWRAP;
 $NOLINKTABLE = 0 unless defined $NOLINKTABLE;
@@ -69,9 +68,8 @@ sub produce {
                 -title => $title,
                 %stylesheet,
                 -meta => { generator => $NAME },
-            });
+            }),
             $q->h1({ -class => 'SchemaDescription' }, $title),
-            $q->a({ -name => 'top' }),
             $q->hr;
     }
 
@@ -85,7 +83,8 @@ sub produce {
         # Leading table of links
         push @html, 
             $q->comment("Table listing ($count)"),
-            $q->start_table({ -width => '100%', -class => 'LinkTable' }),
+            $q->a({ -name => 'top' }),
+            $q->start_table({ -width => '100%', -class => 'LinkTable'}),
 
             # XXX This needs to be colspan="$#{$table->fields}" class="LinkTableHeader"
             $q->Tr(
@@ -96,7 +95,7 @@ sub produce {
                 ),
             );
 
-        for my $table (sort @table_names) {
+        for my $table (@table_names) {
             my $table_name = $table->name;
             push @html, 
                 $q->comment("Start link to table '$table_name'"),
@@ -114,7 +113,8 @@ sub produce {
         my $table_name = $table->name       or next;
         my @fields     = $table->get_fields or next;
         push @html,
-            $q->comment("Starting table '$table_name'");
+            $q->comment("Starting table '$table_name'"),
+            $q->a({ -name => $table_name }),
             $q->table({ -class => 'TableHeader', -width => '100%' },
                 $q->Tr({ -class => 'TableHeaderRow' },
                     $q->td({ -class => 'TableHeaderCell' }, $q->h3($table_name)),
@@ -136,7 +136,7 @@ sub produce {
         # Fields
         #
         push @html,
-            $q->start_table,
+            $q->start_table({ -border => 1 }),
                 $q->Tr(
                     $q->th({ -class => 'FieldHeader' },
                            [ 
@@ -150,6 +150,7 @@ sub produce {
                     ) 
                 );
 
+        my $i = 0;
         for my $field ( @fields ) {
             my $name      = $field->name      || '';
                $name      = qq[<a name="$table_name-$name">$name</a>];
@@ -173,8 +174,10 @@ sub produce {
             push @other, 'UNIQUE'      if $field->is_unique;
             push @other, 'NOT NULL'    unless $field->is_nullable;
             push @other, $comment      if $comment;
+            my $class = $i++ % 2 ? 'even' : 'odd';
             push @html,
                 $q->Tr(
+                    { -class => "tr-$class" },
                     $q->td({ -class => "FieldCellName" }, $name),
                     $q->td({ -class => "FieldCellType" }, $data_type),
                     $q->td({ -class => "FieldCellSize" }, $size),
@@ -209,13 +212,40 @@ sub produce {
             push @html, $q->end_table;
         }
 
+        #
+        # Constraints
+        #
+        my @constraints = 
+            grep { $_->type ne PRIMARY_KEY } $table->get_constraints;
+        if ( @constraints ) {
+            push @html, 
+                $q->h3('Constraints'),
+                $q->start_table({ -border => 1 }),
+                    $q->Tr({ -class => 'IndexRow' },
+                        $q->th([ 'Type', 'Fields' ]) 
+                    );
+
+            for my $c ( @constraints ) {
+                my $type   = $c->type || '';
+                my $fields = join( ', ', $c->fields ) || '';
+
+                push @html,
+                    $q->Tr({ -class => 'IndexCell' },
+                        $q->td( [ $type, $fields ] )
+                    );
+            }
+
+            push @html, $q->end_table;
+        }
+
         push @html, $q->hr;
     }
 
+    my $sqlt_version = $t->version;
     if ($wrap) {
         push @html,
             qq[Created by <a href="http://sqlfairy.sourceforge.net">],
-            qq[SQL::Translator</a>],
+            qq[SQL::Translator $sqlt_version</a>],
             $q->end_html;
     }
 
@@ -301,9 +331,9 @@ nicely spaced and human-readable.  Otherwise, it will have very little
 insignificant whitespace and be generally smaller.
 
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>,
-Darren Chamberlain E<lt>darren@cpan.orgE<gt>
+Darren Chamberlain E<lt>darren@cpan.orgE<gt>.
 
 =cut