From: Mark Addison Date: Fri, 20 Jan 2006 16:17:21 +0000 (+0000) Subject: Intial code for Dia producer X-Git-Tag: v0.11008~472 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=35a1938f8bf01e2941aa3c9f978ba0007a4b2503;p=dbsrgits%2FSQL-Translator.git Intial code for Dia producer --- diff --git a/Changes b/Changes index 77e89f7..b3e58e9 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ * Added mysql_character_set for 4.1+ -mda * Two experimental filters. -mda * Added build support for installing templates. -mda +* Added the initial work on a template based Dia UML producer. -mda # ----------------------------------------------------------- # 0.7 2005-06-10 diff --git a/lib/SQL/Translator/Producer/DiaUml.pm b/lib/SQL/Translator/Producer/DiaUml.pm new file mode 100644 index 0000000..2cbf7a4 --- /dev/null +++ b/lib/SQL/Translator/Producer/DiaUml.pm @@ -0,0 +1,98 @@ +package SQL::Translator::Producer::DiaUml; + +# ------------------------------------------------------------------- +# $Id: DiaUml.pm,v 1.1 2006-01-20 16:17:21 grommit Exp $ +# ------------------------------------------------------------------- +# Copyright (C) 2002-4 SQLFairy Authors +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# 02111-1307 USA +# ------------------------------------------------------------------- + +=pod + +=head1 NAME + +SQL::Translator::Producer::DiaUml - + Produces dia UML diagrams from schema. + +=head1 SYNOPSIS + + use SQL::Translator; + my $translator = SQL::Translator->new( + from => 'MySQL', + filename => 'foo_schema.sql', + to => 'DiaUml', + ); + print $translator->translate; + +=head1 DESCRIPTION + +Currently you will get one class (with the a table +stereotype) generated per table in the schema. The fields are added as +attributes of the classes and their datatypes set. It doesn't currently set any +of the relationships. It doesn't do any layout, all the classses are in one big +stack. However it is still useful as you can use the layout tools in Dia to +automatically arrange them horizontally or vertically. + +=head2 Producer Args + +=over 4 + +=back + +=cut + +# ------------------------------------------------------------------- + +use strict; + +use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; +$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; +$DEBUG = 0 unless defined $DEBUG; + +use SQL::Translator::Utils 'debug'; +use SQL::Translator::ConfigData; +use base qw/SQL::Translator::Producer::TT::Base/; +# Convert produce call into a method call on our class +sub produce { return __PACKAGE__->new( translator => shift )->run; }; + +# Add the installed templates to the inc path. +sub tt_config { + ( INCLUDE_PATH => SQL::Translator::ConfigData->config('template_dir')."/dia_uml" ); +} + +sub tt_schema { 'schema.tt2' } + +1; + +# ------------------------------------------------------------------- + +=pod + +=head1 AUTHOR + +Mark Addison Egrommit@users.sourceforge.netE. + +=head1 TODO + +* Add the foriegn keys from the schema as UML relations. + +* Layout the classes. + +=head1 SEE ALSO + +SQL::Translator. + +=cut diff --git a/templates/dia_uml/diagram b/templates/dia_uml/diagram new file mode 100644 index 0000000..8496cca --- /dev/null +++ b/templates/dia_uml/diagram @@ -0,0 +1,68 @@ + + + + + + + + + + + + + #A4# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% content %] + + diff --git a/templates/dia_uml/layer b/templates/dia_uml/layer new file mode 100644 index 0000000..311da56 --- /dev/null +++ b/templates/dia_uml/layer @@ -0,0 +1,6 @@ +[%- + DEFAULT name="Layer1" visible="true" +%] + + [% content %] + diff --git a/templates/dia_uml/schema.tt2 b/templates/dia_uml/schema.tt2 new file mode 100644 index 0000000..d8488e3 --- /dev/null +++ b/templates/dia_uml/schema.tt2 @@ -0,0 +1,30 @@ +[%# vim:ft=tt2 -%] +[% WRAPPER diagram %] + [% WRAPPER layer name="Background" %] + [% FOREACH table IN schema.get_tables %] + [% INCLUDE 'uml-class-start' + name = table.name + stereotype = 'Table' + visible_operations = 'false' + %] + + [% FOREACH field IN table.get_fields; + SET type = field.data_type; + SET type = "$type($field.size)" IF field.size; + INCLUDE "uml-attribute" + name = field.name + stereotype = 'Field' + type = type + value = field.default_value + ; + END %] + + + + + + + [% INCLUDE 'uml-class-end' %] + [% END %] + [% END %] +[% END %] diff --git a/templates/dia_uml/uml-attribute b/templates/dia_uml/uml-attribute new file mode 100644 index 0000000..1502a8b --- /dev/null +++ b/templates/dia_uml/uml-attribute @@ -0,0 +1,28 @@ +[%# vim:ft=tt2 +-%] +[%- + DEFAULT visibility=0 abstract="false" class_scope="false" +%] + + + #[% name %]# + + + #[% type %]# + + + #[% value %]# + + + #[% comment %]# + + + + + + + + + + + diff --git a/templates/dia_uml/uml-class b/templates/dia_uml/uml-class new file mode 100644 index 0000000..64112c6 --- /dev/null +++ b/templates/dia_uml/uml-class @@ -0,0 +1,14 @@ +[%# vim:ft=tt2 +-%] + [% INCLUDE 'uml-class-start' %] + + [%- FOREACH attributes; + INCLUDE "uml-attribute"; + END %] + + + + + + + [% INCLUDE 'uml-class-end' %] diff --git a/templates/dia_uml/uml-class-all b/templates/dia_uml/uml-class-all new file mode 100644 index 0000000..dfe39cb --- /dev/null +++ b/templates/dia_uml/uml-class-all @@ -0,0 +1,107 @@ +[%# vim:ft=tt2 +-%] + + + + + + + + + + + + + + + + + + #[% name %]# + + + #[% stereotype %]# + + + #[% comment %]# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% FOREACH attributes %] + [% INCLUDE "uml-attribute" %] + [% END %] + + + + + + + diff --git a/templates/dia_uml/uml-class-end b/templates/dia_uml/uml-class-end new file mode 100644 index 0000000..cbee5b7 --- /dev/null +++ b/templates/dia_uml/uml-class-end @@ -0,0 +1,3 @@ +[%# vim:ft=tt2 +-%] + diff --git a/templates/dia_uml/uml-class-start b/templates/dia_uml/uml-class-start new file mode 100644 index 0000000..a96bb11 --- /dev/null +++ b/templates/dia_uml/uml-class-start @@ -0,0 +1,98 @@ +[% # vim:ft=tt2 + DEFAULT + visible_operations='true' +-%] + + + + + + + + + + + + + + + + + + #[% name %]# + + + #[% stereotype %]# + + + #[% comment %]# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +