Bumping version to 1.61
[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
0fe51e8e 25of the relationships. It doesn't do any layout, all the classes are in one big
fae069ed 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
fae069ed 31=cut
32
fae069ed 33use strict;
f27f9229 34use warnings;
fae069ed 35
0c04c5a2 36our @EXPORT_OK;
752a0ffc 37our $VERSION = '1.61';
fae069ed 38
39use SQL::Translator::Utils 'debug';
40
41sub produce {
42 my $translator = shift;
43 my $schema = $translator->schema;
44 my $o = '';
45 for my $table ( $schema->get_tables ) {
46 my $table_name = $table->name or next;
47 my $n = latex($table_name);
48 $o .=
49 sprintf '
50\subsubsection{%s}
51%s
52\begin{table}[htb]
53\caption{%s}
54\label{tab:%s}
55\center
56{ \small
57 \begin{tabular}{l l p{8cm}}
58 Column & Datatype & Description \\\\ \hline
59',
60 $n, latex($table->comments), $n, $table_name;
61
62 foreach my $f ($table->get_fields) {
63 $o .= sprintf '%s & %s & %s \\\\', map {latex($_)} ($f->name, $f->data_type, $f->comments || '');
64 $o .= "\n";
65
66 }
67$o .= sprintf '
68\end{tabular}
69}
70\end{table}
71\clearpage
72';
73 }
74 return $o;
75}
76sub latex {
77 my $s = shift;
78 return '' unless defined $s;
79 $s =~ s/([\&\_\$\{\#])/\\$1/g;
80 return $s;
81}
ea93df61 82
fae069ed 831;
84
fae069ed 85=pod
86
87=head1 AUTHOR
88
ea93df61 89Chris Mungall
fae069ed 90
91=head1 SEE ALSO
92
93SQL::Translator.
94
95=cut