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 | |
31 | =over 4 |
32 | |
33 | =back |
34 | |
35 | =cut |
36 | |
fae069ed |
37 | use strict; |
f27f9229 |
38 | use warnings; |
fae069ed |
39 | |
0c04c5a2 |
40 | our @EXPORT_OK; |
41 | our $VERSION = '1.59'; |
fae069ed |
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 | } |
ea93df61 |
86 | |
fae069ed |
87 | 1; |
88 | |
fae069ed |
89 | =pod |
90 | |
91 | =head1 AUTHOR |
92 | |
ea93df61 |
93 | Chris Mungall |
fae069ed |
94 | |
95 | =head1 SEE ALSO |
96 | |
97 | SQL::Translator. |
98 | |
99 | =cut |