| 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.6_3'; | ||
| 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 | } | ||
| 82 | |||
| 83 | 1; | ||
| 84 | |||
| 85 | =pod | ||
| 86 | |||
| 87 | =head1 AUTHOR | ||
| 88 | |||
| 89 | Chris Mungall | ||
| 90 | |||
| 91 | =head1 SEE ALSO | ||
| 92 | |||
| 93 | SQL::Translator. | ||
| 94 | |||
| 95 | =cut |