Actually there was an empty test for it as well :)
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / Latex.pm
CommitLineData
fae069ed 1package SQL::Translator::Producer::Latex;
2
3# -------------------------------------------------------------------
d4f84dd1 4# $Id: Latex.pm 1440 2009-01-17 16:31:57Z jawnsy $
fae069ed 5# -------------------------------------------------------------------
6# Copyright (C) 2002-6 SQLFairy Authors
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; version 2.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20# 02111-1307 USA
21# -------------------------------------------------------------------
22
23=pod
24
25=head1 NAME
26
27SQL::Translator::Producer::Latex -
28 Produces latex formatted tables ready for import from schema.
29
30=head1 SYNOPSIS
31
32 use SQL::Translator;
33 my $translator = SQL::Translator->new(
34 from => 'MySQL',
35 filename => 'foo_schema.sql',
36 to => 'Latex',
37 );
38 print $translator->translate;
39
40=head1 DESCRIPTION
41
42Currently you will get one class (with the a table
43stereotype) generated per table in the schema. The fields are added as
44attributes of the classes and their datatypes set. It doesn't currently set any
45of the relationships. It doesn't do any layout, all the classses are in one big
46stack. However it is still useful as you can use the layout tools in Dia to
47automatically arrange them horizontally or vertically.
48
49=head2 Producer Args
50
51=over 4
52
53=back
54
55=cut
56
57# -------------------------------------------------------------------
58
59use strict;
60
478f608d 61use vars qw[ $DEBUG @EXPORT_OK ];
fae069ed 62$DEBUG = 0 unless defined $DEBUG;
63
64use SQL::Translator::Utils 'debug';
65
66sub produce {
67 my $translator = shift;
68 my $schema = $translator->schema;
69 my $o = '';
70 for my $table ( $schema->get_tables ) {
71 my $table_name = $table->name or next;
72 my $n = latex($table_name);
73 $o .=
74 sprintf '
75\subsubsection{%s}
76%s
77\begin{table}[htb]
78\caption{%s}
79\label{tab:%s}
80\center
81{ \small
82 \begin{tabular}{l l p{8cm}}
83 Column & Datatype & Description \\\\ \hline
84',
85 $n, latex($table->comments), $n, $table_name;
86
87 foreach my $f ($table->get_fields) {
88 $o .= sprintf '%s & %s & %s \\\\', map {latex($_)} ($f->name, $f->data_type, $f->comments || '');
89 $o .= "\n";
90
91 }
92$o .= sprintf '
93\end{tabular}
94}
95\end{table}
96\clearpage
97';
98 }
99 return $o;
100}
101sub latex {
102 my $s = shift;
103 return '' unless defined $s;
104 $s =~ s/([\&\_\$\{\#])/\\$1/g;
105 return $s;
106}
107
1081;
109
110# -------------------------------------------------------------------
111
112=pod
113
114=head1 AUTHOR
115
116Chris Mungall
117
118=head1 SEE ALSO
119
120SQL::Translator.
121
122=cut