Remove copyright headers from individual scripts
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / Latex.pm
CommitLineData
fae069ed 1package SQL::Translator::Producer::Latex;
2
fae069ed 3=pod
4
5=head1 NAME
6
7SQL::Translator::Producer::Latex -
8 Produces latex formatted tables ready for import from schema.
9
10=head1 SYNOPSIS
11
12 use SQL::Translator;
13 my $translator = SQL::Translator->new(
14 from => 'MySQL',
15 filename => 'foo_schema.sql',
16 to => 'Latex',
17 );
18 print $translator->translate;
19
20=head1 DESCRIPTION
21
22Currently you will get one class (with the a table
23stereotype) generated per table in the schema. The fields are added as
24attributes of the classes and their datatypes set. It doesn't currently set any
25of the relationships. It doesn't do any layout, all the classses are in one big
26stack. However it is still useful as you can use the layout tools in Dia to
27automatically arrange them horizontally or vertically.
28
29=head2 Producer Args
30
31=over 4
32
33=back
34
35=cut
36
37# -------------------------------------------------------------------
38
39use strict;
40
da06ac74 41use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
11ad2df9 42$VERSION = '1.59';
fae069ed 43$DEBUG = 0 unless defined $DEBUG;
44
45use SQL::Translator::Utils 'debug';
46
47sub produce {
48 my $translator = shift;
49 my $schema = $translator->schema;
50 my $o = '';
51 for my $table ( $schema->get_tables ) {
52 my $table_name = $table->name or next;
53 my $n = latex($table_name);
54 $o .=
55 sprintf '
56\subsubsection{%s}
57%s
58\begin{table}[htb]
59\caption{%s}
60\label{tab:%s}
61\center
62{ \small
63 \begin{tabular}{l l p{8cm}}
64 Column & Datatype & Description \\\\ \hline
65',
66 $n, latex($table->comments), $n, $table_name;
67
68 foreach my $f ($table->get_fields) {
69 $o .= sprintf '%s & %s & %s \\\\', map {latex($_)} ($f->name, $f->data_type, $f->comments || '');
70 $o .= "\n";
71
72 }
73$o .= sprintf '
74\end{tabular}
75}
76\end{table}
77\clearpage
78';
79 }
80 return $o;
81}
82sub latex {
83 my $s = shift;
84 return '' unless defined $s;
85 $s =~ s/([\&\_\$\{\#])/\\$1/g;
86 return $s;
87}
88
891;
90
91# -------------------------------------------------------------------
92
93=pod
94
95=head1 AUTHOR
96
11ad2df9 97Chris Mungall
fae069ed 98
99=head1 SEE ALSO
100
101SQL::Translator.
102
103=cut