Commit | Line | Data |
fae069ed |
1 | package SQL::Translator::Producer::Latex; |
2 | |
fae069ed |
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 |
0fe51e8e |
25 | of the relationships. It doesn't do any layout, all the classes are in one big |
fae069ed |
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 | |
fae069ed |
31 | =cut |
32 | |
fae069ed |
33 | use strict; |
f27f9229 |
34 | use warnings; |
fae069ed |
35 | |
0c04c5a2 |
36 | our @EXPORT_OK; |
da93ce68 |
37 | our $VERSION = '1.60'; |
fae069ed |
38 | |
39 | use SQL::Translator::Utils 'debug'; |
40 | |
41 | sub 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 | } |
76 | sub latex { |
77 | my $s = shift; |
78 | return '' unless defined $s; |
79 | $s =~ s/([\&\_\$\{\#])/\\$1/g; |
80 | return $s; |
81 | } |
ea93df61 |
82 | |
fae069ed |
83 | 1; |
84 | |
fae069ed |
85 | =pod |
86 | |
87 | =head1 AUTHOR |
88 | |
ea93df61 |
89 | Chris Mungall |
fae069ed |
90 | |
91 | =head1 SEE ALSO |
92 | |
93 | SQL::Translator. |
94 | |
95 | =cut |