ruby-graphviz 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.9.3 :
2
+ * Minor bug correction for Windows
3
+ * Use Open3.popen3 if installed, else use IO.popen (by Dave Burt)
4
+ * Add '-', '>' and '>>' has aliases of '<<' to create an edge.
5
+
1
6
  0.9.2 :
2
7
  * Escape nodes (by Dave Burt)
3
8
  * Handle errors from graphviz command (by Dave Burt)
data/examples/maketest.sh CHANGED
@@ -22,6 +22,10 @@ ruby sample16.rb
22
22
  ruby sample17.rb
23
23
  ruby sample18.rb
24
24
  ruby sample19.rb
25
+ ruby sample20.rb
26
+ ruby sample21.rb
27
+ ruby sample22.rb
28
+ ruby sample23.rb
25
29
 
26
30
  ruby testorder.rb $1
27
31
  ruby testxml.rb $1
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift( "../lib" );
4
+ require "graphviz"
5
+
6
+ GraphViz::new( "G" ) { |g|
7
+ g.hello << g.world
8
+ g.bonjour - g.monde
9
+ g.hola > g.mundo
10
+ g.holla >> g.welt
11
+ }.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
Binary file
data/lib/graphviz.rb CHANGED
@@ -16,7 +16,6 @@
16
16
 
17
17
  require 'tempfile'
18
18
  require 'mkmf'
19
- require 'open3'
20
19
 
21
20
  require 'graphviz/node'
22
21
  require 'graphviz/edge'
@@ -324,7 +323,7 @@ class GraphViz
324
323
  else
325
324
  if hOpt.nil? == false and hOpt[0].nil? == false
326
325
  hOpt[0].each do |xKey, xValue|
327
- xValue = xValue.to_s unless xValue.nil? or xValue.class == Class
326
+ xValue = xValue.to_s unless xValue.nil? or [Class, TrueClass, FalseClass].include?(xValue.class)
328
327
  case xKey.to_s
329
328
  when "output"
330
329
  warn ":output option is deprecated, please use :<format> => :<file>"
@@ -356,12 +355,14 @@ class GraphViz
356
355
  xOutputString = false
357
356
  xOutput = if @format != "none"
358
357
  ## Act: Save script and send it to dot
359
- t = Tempfile::open( File.basename($0) + "." )
358
+ t = if /Windows/.match( ENV['OS'] )
359
+ Tempfile::open( File.basename($0), "." )
360
+ else
361
+ Tempfile::open( File.basename($0) )
362
+ end
360
363
  t.print( xDOTScript )
361
364
  t.close
362
365
 
363
- #cmd = find_executable( @prog )
364
- #cmd = find_executable0( @prog )
365
366
  cmd = find_executable( )
366
367
  if cmd == nil
367
368
  raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option"
@@ -390,21 +391,13 @@ class GraphViz
390
391
  end
391
392
  end
392
393
 
393
- xCmd = "#{cmd} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
394
-
395
- #f = IO.popen( xCmd )
396
- #print f.readlines
397
- #f.close
398
- Open3.popen3( xCmd ) do |_, stdout, stderr|
399
- errors = stderr.read
400
- if errors.blank?
401
- stdout.read
402
- else
403
- raise "Error from graphviz (#{xCmd}):\n#{errors}"
404
- end
405
- end
394
+ #xCmd = "#{cmd} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
395
+ #if /Windows/.match( ENV['OS'] )
396
+ xCmd = "\"#{cmd}\" #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
397
+ #end
398
+
399
+ output_from_command( xCmd )
406
400
  else
407
- #puts xDOTScript
408
401
  xDOTScript
409
402
  end
410
403
 
@@ -418,6 +411,35 @@ class GraphViz
418
411
 
419
412
  alias :save :output
420
413
 
414
+ def output_and_errors_from_command(cmd) #:nodoc:
415
+ unless defined? Open3
416
+ begin
417
+ require 'open3'
418
+ require 'win32/open3'
419
+ rescue LoadError
420
+ end
421
+ end
422
+ begin
423
+ Open3.popen3( cmd ) do |stdin, stdout, stderr|
424
+ stdin.close
425
+ [stdout.read, stderr.read]
426
+ end
427
+ rescue NotImplementedError, NoMethodError
428
+ IO.popen( cmd ) do |stdout|
429
+ [stdout.read, nil]
430
+ end
431
+ end
432
+ end
433
+
434
+ def output_from_command(cmd) #:nodoc:
435
+ output, errors = output_and_errors_from_command(cmd)
436
+ if errors.nil? || errors.strip.empty?
437
+ output
438
+ else
439
+ raise "Error from #{cmd}:\n#{errors}"
440
+ end
441
+ end
442
+
421
443
  #
422
444
  # Get the graph name
423
445
  #
@@ -439,6 +461,9 @@ class GraphViz
439
461
  return GraphViz::commonGraph( oNode, self ).add_edge( self, oNode )
440
462
  end
441
463
  end
464
+ alias :> :<<
465
+ alias :- :<<
466
+ alias :>> :<<
442
467
 
443
468
  def pg #:nodoc:
444
469
  @oParentGraph
@@ -15,7 +15,7 @@
15
15
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
  module Constants
18
- RGV_VERSION = "0.9.2"
18
+ RGV_VERSION = "0.9.3"
19
19
 
20
20
  ## Const: Output formats
21
21
  FORMATS = [
data/lib/graphviz/edge.rb CHANGED
@@ -71,6 +71,10 @@ class GraphViz
71
71
 
72
72
  GraphViz::commonGraph( oNode, n ).add_edge( n, oNode )
73
73
  end
74
+ alias :> :<<
75
+ alias :- :<<
76
+ alias :>> :<<
77
+
74
78
  #
75
79
  # Set edge attributs
76
80
  #
data/lib/graphviz/node.rb CHANGED
@@ -71,6 +71,9 @@ class GraphViz
71
71
  return GraphViz::commonGraph( oNode, self ).add_edge( self, oNode )
72
72
  end
73
73
  end
74
+ alias :> :<<
75
+ alias :- :<<
76
+ alias :>> :<<
74
77
 
75
78
  #
76
79
  # Set node attributs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Lejeune
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-15 00:00:00 +02:00
12
+ date: 2009-10-19 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,8 @@ files:
84
84
  - examples/sample21.rb
85
85
  - examples/sample22.rb
86
86
  - examples/sample23.rb
87
+ - examples/sample24.rb
88
+ - examples/sample24.rb.png
87
89
  - examples/shapes.rb
88
90
  - examples/test.xml
89
91
  - examples/testorder.rb
@@ -101,8 +103,11 @@ homepage: http://raa.ruby-lang.org/project/ruby-graphviz/
101
103
  licenses: []
102
104
 
103
105
  post_install_message: |+
104
- Since version 0.9.2, Ruby/GraphViz use Open3.popen3.
105
- On Windows, you need to install win32-open3
106
+
107
+ Since version 0.9.2, Ruby/GraphViz can use Open3.popen3 (or not)
108
+ On Windows, you can install 'win32-open3'
109
+
110
+ You need to install GraphViz (http://graphviz.org/) to use this Gem.
106
111
 
107
112
  rdoc_options:
108
113
  - --title