ruby-graphviz 0.9.13 → 0.9.14

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -17,6 +17,11 @@ Interface to the GraphViz graphing tool
17
17
 
18
18
  == CHANGELOG
19
19
 
20
+ === 0.9.14 :
21
+ * Add dot2ruby script
22
+ * Remove NULL character in the DOT script
23
+ * <b>WARNING</b> : FamilyTree is (still) broken in this version !
24
+
20
25
  === 0.9.13 :
21
26
  * Add dot2ruby.g
22
27
  * Bug correction with HTML label
@@ -193,11 +198,29 @@ Ruby/GraphViz also include :
193
198
 
194
199
  * ruby2gv, a simple tool that's allow you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
195
200
 
196
- ruby2gv -Tpng -oruby2gv.png ruby2gv
201
+ ruby2gv -Tpng -oruby2gv.png ruby2gv
197
202
 
198
203
  * gem2gv, a tools that's allow you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
199
204
 
200
- gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
205
+ gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
206
+
207
+ * dot2ruby, a tools that's allow you to create a ruby script from a graphviz script
208
+
209
+ $ cat hello.dot
210
+ digraph G {Hello->World;}
211
+
212
+ $ dot2ruby hello.dot
213
+ # This code was generated by dot2ruby.g
214
+
215
+ require 'rubygems'
216
+ require 'graphviz'
217
+ graph_g = GraphViz.digraph( "G" ) { |graph_g|
218
+ graph_g[:bb] = '0,0,70,108'
219
+ node_hello = graph_g.add_node( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
220
+ graph_g.add_edge( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
221
+ node_world = graph_g.add_node( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
222
+ }
223
+ puts graph_g.output( :canon => String )
201
224
 
202
225
  At last, you can create familly tree with GraphViz::FamilyTree (<b>beta</b>) :
203
226
 
data/bin/dot2ruby ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require 'rubygems'
19
+ require 'graphviz/constants'
20
+ require 'graphviz/ext'
21
+ require 'graphviz/utils'
22
+ require 'getoptlong'
23
+
24
+ class Dot2Ruby
25
+ include GVUtils
26
+
27
+ def initialize( xGVPath, xUse, xOutFile )
28
+ paths = (xGVPath.nil?) ? [] : [xGVPath]
29
+ @xUsePath = find_executable( xUse, paths )
30
+ @xGvprPath = find_executable( 'gvpr', paths )
31
+ @xOutFile = xOutFile
32
+ @gvprScript = GraphViz::Ext.find( "dot2ruby.g" )
33
+ end
34
+
35
+ def run( xFile )
36
+ xCmd = "#{@xUsePath} #{xFile} | #{@xGvprPath} -f #{@gvprScript}"
37
+ xOutput = output_from_command( xCmd )
38
+ if @xOutFile.nil?
39
+ puts xOutput
40
+ else
41
+ File.open( @xOutFile, "w" ) do |io|
42
+ io.print xOutput
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def usage
49
+ puts "usage: dot2ruby [-ofile] [-h] [-V] script"
50
+ puts "-o, --output-file file Output file (default: STDOUT)"
51
+ puts "-p, --path Graphviz path"
52
+ puts "-u, --use PROGRAM Program to use (default: dot)"
53
+ puts "-V, --version Show version"
54
+ puts "-h, --help Show this usage message"
55
+ end
56
+
57
+ def version
58
+ puts "Dot2Ruby v#{Constants::RGV_VERSION}, (c) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
59
+ puts ""
60
+ puts "This program is free software; you can redistribute it and/or modify"
61
+ puts "it under the terms of the GNU General Public License as published by"
62
+ puts "the Free Software Foundation; either version 2 of the License, or"
63
+ puts "(at your option) any later version."
64
+ puts ""
65
+ puts "This program is distributed in the hope that it will be useful,"
66
+ puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
67
+ puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
68
+ puts "GNU General Public License for more details."
69
+ puts ""
70
+ puts "You should have received a copy of the GNU General Public License"
71
+ puts "along with this program; if not, write to the Free Software"
72
+ puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
73
+ end
74
+
75
+ xOutFile = nil
76
+ xGVPath = nil
77
+ xUse = "dot"
78
+
79
+ oOpt = GetoptLong.new(
80
+ ['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
81
+ ['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
82
+ ['--use', '-u', GetoptLong::REQUIRED_ARGUMENT],
83
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
84
+ ['--version', '-V', GetoptLong::NO_ARGUMENT]
85
+ )
86
+
87
+ begin
88
+ oOpt.each_option do |xOpt, xValue|
89
+ case xOpt
90
+ when '--output-file'
91
+ xOutFile = xValue
92
+ when '--path'
93
+ xGVPath = xValue
94
+ when '--use'
95
+ xUse = xValue
96
+ when '--help'
97
+ usage( )
98
+ exit
99
+ when '--version'
100
+ version( )
101
+ exit
102
+ end
103
+ end
104
+ rescue GetoptLong::InvalidOption => e
105
+ usage( )
106
+ exit
107
+ end
108
+
109
+ xFile = ARGV[0]
110
+
111
+ if xFile.nil? == true
112
+ usage( )
113
+ exit
114
+ end
115
+
116
+ Dot2Ruby::new( xGVPath, xUse, xOutFile ).run( xFile )
data/lib/graphviz.rb CHANGED
@@ -20,6 +20,7 @@ IS_CYGWIN = ((RUBY_PLATFORM =~ /cygwin/) != nil)
20
20
 
21
21
  require 'tempfile'
22
22
 
23
+ require 'graphviz/utils'
23
24
  require 'graphviz/node'
24
25
  require 'graphviz/edge'
25
26
  require 'graphviz/attrs'
@@ -32,6 +33,7 @@ $KCODE = "UTF8"
32
33
 
33
34
  class GraphViz
34
35
  include Constants
36
+ include GVUtils
35
37
 
36
38
  public
37
39
 
@@ -434,7 +436,7 @@ class GraphViz
434
436
 
435
437
  @output = hOutput if hOutput.size > 0
436
438
 
437
- xDOTScript = "#{@oGraphType} #{@name} {\n" << xDOTScript
439
+ xDOTScript = ("#{@oGraphType} #{@name} {\n" << xDOTScript).gsub( /\0/, "" )
438
440
 
439
441
  xOutputString = (@filename == String ||
440
442
  @output.any? {|format, file| file == String })
@@ -523,37 +525,6 @@ class GraphViz
523
525
  end
524
526
 
525
527
  alias :save :output
526
-
527
- def output_and_errors_from_command(cmd) #:nodoc:
528
- unless defined? Open3
529
- begin
530
- require 'open3'
531
- require 'win32/open3'
532
- rescue LoadError
533
- end
534
- end
535
- begin
536
- Open3.popen3( cmd ) do |stdin, stdout, stderr|
537
- stdin.close
538
- stdout.binmode
539
- [stdout.read, stderr.read]
540
- end
541
- rescue NotImplementedError, NoMethodError
542
- IO.popen( cmd ) do |stdout|
543
- stdout.binmode
544
- [stdout.read, nil]
545
- end
546
- end
547
- end
548
-
549
- def output_from_command(cmd) #:nodoc:
550
- output, errors = output_and_errors_from_command(cmd)
551
- if errors.nil? || errors.strip.empty?
552
- output
553
- else
554
- raise "Error from #{cmd}:\n#{errors}"
555
- end
556
- end
557
528
 
558
529
  #
559
530
  # Get the graph name
@@ -763,67 +734,4 @@ class GraphViz
763
734
  end
764
735
  end
765
736
 
766
- # Since this code is an adaptation of Launchy::Application#find_executable
767
- # (http://copiousfreetime.rubyforge.org/launchy/Launchy/Application.html)
768
- # it follow is licence :
769
- #
770
- # Permission to use, copy, modify, and/or distribute this software for any
771
- # purpose with or without fee is hereby granted, provided that the above
772
- # copyright notice and this permission notice appear in all copies.
773
- #
774
- # THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
775
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
776
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
777
- # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
778
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
779
- # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
780
- # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
781
- def find_executable(bin, paths) #:nodoc:
782
- paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.nil? or paths.empty?
783
-
784
- paths.each do |path|
785
- file = (path.nil?)?bin:File.join(path,bin)
786
- if File.executable?(file) and not File.directory?(file) then
787
- return file
788
- elsif RUBY_PLATFORM =~ /mswin|mingw/
789
- found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file + ext) }
790
- return file + found_ext if found_ext
791
- end
792
- end
793
- return nil
794
- end
795
- # def find_executable(bin = @prog, *paths) #:nodoc:
796
- #
797
- # paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
798
- # paths.each do |path|
799
- # file = File.join(path, add_exe_suffix(bin))
800
- # if File.executable?(file) then
801
- # return file
802
- # end
803
- # end
804
- # return nil
805
- # end
806
-
807
- def add_exe_suffix(prog) #:nodoc:
808
- if /Windows/.match( ENV['OS'] )
809
- suffix = '.exe'
810
- else
811
- suffix = ''
812
- end
813
- "#{prog}#{suffix}"
814
- end
815
-
816
- def escape_path_containing_blanks(path) #:nodoc:
817
- path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
818
- path_elements = path.split(File::SEPARATOR)
819
- path_elements.map! do |element|
820
- if element.include?(' ')
821
- "\"#{element}\""
822
- else
823
- element
824
- end
825
- end
826
- path_elements.join(File::SEPARATOR)
827
- end
828
-
829
737
  end
@@ -40,7 +40,7 @@
40
40
  # C => cluster
41
41
  #
42
42
  module Constants
43
- RGV_VERSION = "0.9.13"
43
+ RGV_VERSION = "0.9.14"
44
44
 
45
45
  ## Const: Output formats
46
46
  FORMATS = [
@@ -0,0 +1,17 @@
1
+ require 'find'
2
+
3
+ class GraphViz
4
+ class Ext
5
+ def self.find( ext = nil )
6
+ myPath = File.join( File.dirname( File.expand_path( __FILE__ ) ), "..", "ext" )
7
+ found = myPath
8
+ unless ext.nil?
9
+ Find.find(myPath) do |path|
10
+ found = path if File.basename( path ) == ext
11
+ end
12
+ end
13
+
14
+ File.expand_path( found )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,76 @@
1
+ module GVUtils
2
+ # Since this code is an adaptation of Launchy::Application#find_executable
3
+ # (http://copiousfreetime.rubyforge.org/launchy/Launchy/Application.html)
4
+ # it follow is licence :
5
+ #
6
+ # Permission to use, copy, modify, and/or distribute this software for any
7
+ # purpose with or without fee is hereby granted, provided that the above
8
+ # copyright notice and this permission notice appear in all copies.
9
+ #
10
+ # THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13
+ # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15
+ # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ def find_executable(bin, paths) #:nodoc:
18
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.nil? or paths.empty?
19
+
20
+ paths.each do |path|
21
+ file = (path.nil?)?bin:File.join(path,bin)
22
+ if File.executable?(file) and not File.directory?(file) then
23
+ return file
24
+ elsif RUBY_PLATFORM =~ /mswin|mingw/
25
+ found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file + ext) }
26
+ return file + found_ext if found_ext
27
+ end
28
+ end
29
+ return nil
30
+ end
31
+
32
+ def escape_path_containing_blanks(path) #:nodoc:
33
+ path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
34
+ path_elements = path.split(File::SEPARATOR)
35
+ path_elements.map! do |element|
36
+ if element.include?(' ')
37
+ "\"#{element}\""
38
+ else
39
+ element
40
+ end
41
+ end
42
+ path_elements.join(File::SEPARATOR)
43
+ end
44
+
45
+ def output_and_errors_from_command(cmd) #:nodoc:
46
+ unless defined? Open3
47
+ begin
48
+ require 'open3'
49
+ require 'win32/open3'
50
+ rescue LoadError
51
+ end
52
+ end
53
+ begin
54
+ Open3.popen3( cmd ) do |stdin, stdout, stderr|
55
+ stdin.close
56
+ stdout.binmode
57
+ [stdout.read, stderr.read]
58
+ end
59
+ rescue NotImplementedError, NoMethodError
60
+ IO.popen( cmd ) do |stdout|
61
+ stdout.binmode
62
+ [stdout.read, nil]
63
+ end
64
+ end
65
+ end
66
+
67
+ def output_from_command(cmd) #:nodoc:
68
+ output, errors = output_and_errors_from_command(cmd)
69
+ if errors.nil? || errors.strip.empty?
70
+ output
71
+ else
72
+ raise "Error from #{cmd}:\n#{errors}"
73
+ end
74
+ end
75
+
76
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 39
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 13
10
- version: 0.9.13
9
+ - 14
10
+ version: 0.9.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gregoire Lejeune
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-06 00:00:00 +02:00
18
+ date: 2010-07-12 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -37,6 +37,7 @@ email: gregoire.lejeune@free.fr
37
37
  executables:
38
38
  - ruby2gv
39
39
  - gem2gv
40
+ - dot2ruby
40
41
  extensions: []
41
42
 
42
43
  extra_rdoc_files:
@@ -48,6 +49,7 @@ files:
48
49
  - README.rdoc
49
50
  - AUTHORS
50
51
  - setup.rb
52
+ - bin/dot2ruby
51
53
  - bin/gem2gv
52
54
  - bin/ruby2gv
53
55
  - examples/dot/balanced.dot
@@ -132,13 +134,12 @@ files:
132
134
  - examples/simpsons.gv
133
135
  - examples/test.xml
134
136
  - lib/ext/gvpr/dot2ruby.g
135
- - lib/ext/gvpr/toto.gv
136
- - lib/ext/gvpr/toto.rb
137
137
  - lib/graphviz/attrs.rb
138
138
  - lib/graphviz/constants.rb
139
139
  - lib/graphviz/core_ext.rb
140
140
  - lib/graphviz/dot.treetop
141
141
  - lib/graphviz/edge.rb
142
+ - lib/graphviz/ext.rb
142
143
  - lib/graphviz/family_tree/couple.rb
143
144
  - lib/graphviz/family_tree/generation.rb
144
145
  - lib/graphviz/family_tree/person.rb
@@ -152,6 +153,7 @@ files:
152
153
  - lib/graphviz/types/html_string.rb
153
154
  - lib/graphviz/types/lbl_string.rb
154
155
  - lib/graphviz/types.rb
156
+ - lib/graphviz/utils.rb
155
157
  - lib/graphviz/xml.rb
156
158
  - lib/graphviz.rb
157
159
  - test/support.rb