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