| 1 | #------------------------------------------------------------------------------ | ||
| 2 | # DBO::Visitor::RenderHTML - render record as HTML | ||
| 3 | # | ||
| 4 | # DESCRIPTION | ||
| 5 | # A visitor class that renders a record as HTML. | ||
| 6 | # | ||
| 7 | # AUTHOR | ||
| 8 | # Gareth Rees | ||
| 9 | # | ||
| 10 | # COPYRIGHT | ||
| 11 | # Copyright (c) 1999 Canon Research Centre Europe Ltd/ | ||
| 12 | # | ||
| 13 | # $Id$ | ||
| 14 | #------------------------------------------------------------------------------ | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | package DBO::Visitor::RenderHTML; | ||
| 18 | use base qw(DBO::Visitor); | ||
| 19 | use Class::Multimethods; | ||
| 20 | use HTML::FromText 'text2html'; | ||
| 21 | |||
| 22 | multimethod visit_table => | ||
| 23 | qw(DBO::Visitor::RenderHTML DBO::Table DBO::Handle) => | ||
| 24 | sub { | ||
| 25 | my ($vis, $table, $handle) = @_; | ||
| 26 | my @html = ("<BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0>\n"); | ||
| 27 | $vis->{html} = \@html; | ||
| 28 | # visit_table(superclass($vis), $table, $handle); | ||
| 29 | call_next_method(); | ||
| 30 | push @html, "</TABLE></BLOCKQUOTE>\n"; | ||
| 31 | join '', @html; | ||
| 32 | }; | ||
| 33 | |||
| 34 | multimethod visit_column => | ||
| 35 | qw(DBO::Visitor::RenderHTML DBO::Column::String DBO::Handle) => | ||
| 36 | sub { | ||
| 37 | my ($vis, $col, $handle) = @_; | ||
| 38 | my $name = defined $col->{print_name} ? $col->{print_name} : $col->{name}; | ||
| 39 | my $value = $vis->{record}{$col->{name}}; | ||
| 40 | push @{$vis->{html}}, | ||
| 41 | ("<TR VALIGN=\"TOP\"><TD ALIGN=\"RIGHT\">", | ||
| 42 | text2html($name), "</TD>\n<TD ALIGN=\"LEFT\">", | ||
| 43 | text2html($value), "</TD></TR>\n") if defined $value; | ||
| 44 | }; | ||
| 45 | |||
| 46 | multimethod visit_column => | ||
| 47 | qw(DBO::Visitor::RenderHTML DBO::Column::Number DBO::Handle) => | ||
| 48 | sub { | ||
| 49 | my ($vis, $col, $handle) = @_; | ||
| 50 | my $name = defined $col->{print_name} ? $col->{print_name} : $col->{name}; | ||
| 51 | my $value = $vis->{record}{$col->{name}}; | ||
| 52 | push @{$vis->{html}}, | ||
| 53 | ("<TR VALIGN=\"TOP\"><TD ALIGN=\"RIGHT\">", | ||
| 54 | text2html($name), "</TD>\n<TD ALIGN=\"LEFT\">", | ||
| 55 | $vis->{record}{$col->{name}}, "</TD></TR>\n") if defined $value; | ||
| 56 | }; | ||
| 57 | |||
| 58 | 1; |