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