« blib/lib/SQL/Translator/Schema/IndexField.pm
↑ Summary
blib/lib/SQL/Translator/Producer/TT/Base.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 | =cut | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | |||
| 36 | our @EXPORT_OK; | ||
| 37 | our $VERSION = '1.66'; | ||
| 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 .= sprintf ' | ||
| 49 | \subsubsection{%s} | ||
| 50 | %s | ||
| 51 | \begin{table}[htb] | ||
| 52 | \caption{%s} | ||
| 53 | \label{tab:%s} | ||
| 54 | \center | ||
| 55 | { \small | ||
| 56 | \begin{tabular}{l l p{8cm}} | ||
| 57 | Column & Datatype & Description \\\\ \hline | ||
| 58 | ', $n, latex($table->comments), $n, $table_name; | ||
| 59 | |||
| 60 | foreach my $f ($table->get_fields) { | ||
| 61 | $o .= sprintf '%s & %s & %s \\\\', map { latex($_) } ($f->name, $f->data_type, $f->comments || ''); | ||
| 62 | $o .= "\n"; | ||
| 63 | |||
| 64 | } | ||
| 65 | $o .= sprintf ' | ||
| 66 | \end{tabular} | ||
| 67 | } | ||
| 68 | \end{table} | ||
| 69 | \clearpage | ||
| 70 | '; | ||
| 71 | } | ||
| 72 | return $o; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub latex { | ||
| 76 | my $s = shift; | ||
| 77 | return '' unless defined $s; | ||
| 78 | $s =~ s/([\&\_\$\{\#])/\\$1/g; | ||
| 79 | return $s; | ||
| 80 | } | ||
| 81 | |||
| 82 | 1; | ||
| 83 | |||
| 84 | =pod | ||
| 85 | |||
| 86 | =head1 AUTHOR | ||
| 87 | |||
| 88 | Chris Mungall | ||
| 89 | |||
| 90 | =head1 SEE ALSO | ||
| 91 | |||
| 92 | SQL::Translator. | ||
| 93 | |||
| 94 | =cut |