ruby-graphviz 0.9.14 → 0.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +39 -28
- data/bin/dot2ruby +9 -34
- data/bin/git2gv +169 -0
- data/examples/dot/hello_test.rb +1 -1
- data/examples/dot/test_parse.rb +2 -2
- data/examples/sample49.rb +1 -1
- data/examples/sample56.rb +10 -0
- data/lib/ext/gvpr/dot2ruby.g +23 -4
- data/lib/graphviz.rb +31 -4
- data/lib/graphviz/constants.rb +1 -1
- data/lib/graphviz/dot2ruby.rb +50 -0
- data/test/test_examples.rb +1 -1
- metadata +9 -5
data/README.rdoc
CHANGED
@@ -17,6 +17,13 @@ Interface to the GraphViz graphing tool
|
|
17
17
|
|
18
18
|
== CHANGELOG
|
19
19
|
|
20
|
+
=== 0.9.15 :
|
21
|
+
* Add <tt>GraphViz.parser2</tt>. <b>WARNING</b> this method will replace <tt>GraphViz.parser</tt>. So please don't use it, or only for testing.
|
22
|
+
* Bug correction in <tt>dot2ruby</tt>
|
23
|
+
* Add <tt>--output-format</tt> option to <tt>dot2ruby</tt>
|
24
|
+
* Add <tt>git2gv</tt>
|
25
|
+
* Issue #16 : escape graph ID
|
26
|
+
|
20
27
|
=== 0.9.14 :
|
21
28
|
* Add dot2ruby script
|
22
29
|
* Remove NULL character in the DOT script
|
@@ -194,34 +201,6 @@ Create a graph from a file
|
|
194
201
|
}
|
195
202
|
}.output(:png => "sample.png")
|
196
203
|
|
197
|
-
Ruby/GraphViz also include :
|
198
|
-
|
199
|
-
* ruby2gv, a simple tool that's allow you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
|
200
|
-
|
201
|
-
ruby2gv -Tpng -oruby2gv.png ruby2gv
|
202
|
-
|
203
|
-
* gem2gv, a tools that's allow you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
|
204
|
-
|
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 )
|
224
|
-
|
225
204
|
At last, you can create familly tree with GraphViz::FamilyTree (<b>beta</b>) :
|
226
205
|
|
227
206
|
require 'graphviz/family_tree'
|
@@ -250,6 +229,38 @@ At last, you can create familly tree with GraphViz::FamilyTree (<b>beta</b>) :
|
|
250
229
|
|
251
230
|
tree.graph.save( :png => "#{$0}.png" )
|
252
231
|
|
232
|
+
== TOOLS
|
233
|
+
|
234
|
+
Ruby/GraphViz also include :
|
235
|
+
|
236
|
+
* <tt>ruby2gv</tt>, a simple tool that's allow you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
|
237
|
+
|
238
|
+
ruby2gv -Tpng -oruby2gv.png ruby2gv
|
239
|
+
|
240
|
+
* <tt>gem2gv</tt>, a tools that's allow you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
|
241
|
+
|
242
|
+
gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
|
243
|
+
|
244
|
+
* <tt>dot2ruby</tt>, a tools that's allow you to create a ruby script from a graphviz script
|
245
|
+
|
246
|
+
$ cat hello.dot
|
247
|
+
digraph G {Hello->World;}
|
248
|
+
|
249
|
+
$ dot2ruby hello.dot
|
250
|
+
# This code was generated by dot2ruby.g
|
251
|
+
|
252
|
+
require 'rubygems'
|
253
|
+
require 'graphviz'
|
254
|
+
graph_g = GraphViz.digraph( "G" ) { |graph_g|
|
255
|
+
graph_g[:bb] = '0,0,70,108'
|
256
|
+
node_hello = graph_g.add_node( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
|
257
|
+
graph_g.add_edge( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
|
258
|
+
node_world = graph_g.add_node( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
|
259
|
+
}
|
260
|
+
puts graph_g.output( :canon => String )
|
261
|
+
|
262
|
+
* <tt>git2gv</tt>, a tools that's allow you to show your git commits : http://dl.dropbox.com/u/72629/ruby-graphviz-git.svg
|
263
|
+
|
253
264
|
== INSTALLATION
|
254
265
|
|
255
266
|
sudo gem install ruby-graphviz
|
data/bin/dot2ruby
CHANGED
@@ -17,39 +17,14 @@
|
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
19
|
require 'graphviz/constants'
|
20
|
-
require 'graphviz/
|
21
|
-
require 'graphviz/utils'
|
20
|
+
require 'graphviz/dot2ruby'
|
22
21
|
require 'getoptlong'
|
23
22
|
|
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
23
|
def usage
|
49
|
-
puts "usage: dot2ruby [-ofile] [-h] [-V] script"
|
50
|
-
puts "-o, --output-file file Output file
|
24
|
+
puts "usage: dot2ruby [-ofile] [-Tformat] [-h] [-V] script"
|
25
|
+
puts "-o, --output-file file Output file"
|
26
|
+
puts "-T, --output-format format Output format (default: nil)"
|
51
27
|
puts "-p, --path Graphviz path"
|
52
|
-
puts "-u, --use PROGRAM Program to use (default: dot)"
|
53
28
|
puts "-V, --version Show version"
|
54
29
|
puts "-h, --help Show this usage message"
|
55
30
|
end
|
@@ -74,12 +49,12 @@ end
|
|
74
49
|
|
75
50
|
xOutFile = nil
|
76
51
|
xGVPath = nil
|
77
|
-
|
52
|
+
xOutFormat = nil
|
78
53
|
|
79
54
|
oOpt = GetoptLong.new(
|
80
55
|
['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
56
|
+
['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
|
81
57
|
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
82
|
-
['--use', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
83
58
|
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
84
59
|
['--version', '-V', GetoptLong::NO_ARGUMENT]
|
85
60
|
)
|
@@ -89,10 +64,10 @@ begin
|
|
89
64
|
case xOpt
|
90
65
|
when '--output-file'
|
91
66
|
xOutFile = xValue
|
67
|
+
when '--output-format'
|
68
|
+
xOutFormat = xValue
|
92
69
|
when '--path'
|
93
70
|
xGVPath = xValue
|
94
|
-
when '--use'
|
95
|
-
xUse = xValue
|
96
71
|
when '--help'
|
97
72
|
usage( )
|
98
73
|
exit
|
@@ -113,4 +88,4 @@ if xFile.nil? == true
|
|
113
88
|
exit
|
114
89
|
end
|
115
90
|
|
116
|
-
Dot2Ruby::new( xGVPath,
|
91
|
+
Dot2Ruby::new( xGVPath, xOutFile, xOutFormat ).run( xFile )
|
data/bin/git2gv
ADDED
@@ -0,0 +1,169 @@
|
|
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 'getoptlong'
|
20
|
+
require 'graphviz'
|
21
|
+
|
22
|
+
class Git2Gv
|
23
|
+
def initialize( xGVPath, xOutFile, xOutFormat, bNothugly )
|
24
|
+
@xGVPath, @xOutFile, @xOutFormat, @bNothugly = xGVPath, xOutFile, xOutFormat.to_sym, bNothugly
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
git = GraphViz.new( :G, :path => @xGVPath )
|
29
|
+
|
30
|
+
git.node[:shape => "record"]
|
31
|
+
|
32
|
+
branches.each do |branch|
|
33
|
+
git.add_node( branch, :style => "filled", :fillcolor => :lightgrey )
|
34
|
+
end
|
35
|
+
|
36
|
+
commits.each do |commit|
|
37
|
+
git.add_node(
|
38
|
+
commit[:short],
|
39
|
+
:style => "filled",
|
40
|
+
:fillcolor => :lightblue,
|
41
|
+
:label => "{ #{commit[:long]} |{ #{commit[:comment].gsub(/\{/, "\\{").gsub(/\}/, "\\}").gsub(/\|/, "\\|").gsub(/</, "\\<").gsub(/>/, "\\>")}}| { #{commit[:commiter]} | #{commit[:date]} } }"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
refs.each do |from, to|
|
46
|
+
git.add_edge( from, to )
|
47
|
+
end
|
48
|
+
|
49
|
+
relations.each do |from, to|
|
50
|
+
git.add_edge( to, from, :dir => "back" )
|
51
|
+
end
|
52
|
+
|
53
|
+
git.output( @xOutFormat => @xOutFile, :nothugly => @bNothugly )
|
54
|
+
end
|
55
|
+
|
56
|
+
# private
|
57
|
+
def cmd(c, &blk)
|
58
|
+
`#{c}`.split($/).map(&blk || proc {|a| a })
|
59
|
+
end
|
60
|
+
|
61
|
+
def commits
|
62
|
+
@commits ||= begin
|
63
|
+
data = []
|
64
|
+
cmd('git log --pretty=format:"%h - %H - %s - %cn - %cd" --date=short').each do |commit|
|
65
|
+
x = commit.split( " - " )
|
66
|
+
data << {
|
67
|
+
:short => x[0],
|
68
|
+
:long => x[1],
|
69
|
+
:comment => x[2],
|
70
|
+
:commiter => x[3],
|
71
|
+
:date => x[4]
|
72
|
+
}
|
73
|
+
end
|
74
|
+
data
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def relations
|
79
|
+
@rels ||= cmd("git log --pretty=format:\"%h %p\"") { |l|
|
80
|
+
c, *parents = l.split
|
81
|
+
parents.map {|p| [p, c] }
|
82
|
+
}.flatten(1)
|
83
|
+
end
|
84
|
+
|
85
|
+
def branches
|
86
|
+
@branches ||= cmd("git branch") {|b| b[2..-1] }
|
87
|
+
end
|
88
|
+
|
89
|
+
def refs
|
90
|
+
branches.inject({}) {|h,b|
|
91
|
+
h.tap { h[b] = `git log -1 #{b} --pretty=format:"%h"` }
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def current_branch
|
96
|
+
cmd("git branch").select {|l| l =~ /^\*/ }.first.strip[2..-1]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def usage
|
101
|
+
puts "usage: git2gv [-Tformat] [-ofile] [-h] [-V]"
|
102
|
+
puts "-T, --output-format format Output format (default: png)"
|
103
|
+
puts " --nothugly Use nothugly if SVG output"
|
104
|
+
puts "-o, --output-file file Output file (default: STDOUT)"
|
105
|
+
puts "-p, --path Graphviz path"
|
106
|
+
puts "-V, --version Show version"
|
107
|
+
puts "-h, --help Show this usage message"
|
108
|
+
end
|
109
|
+
|
110
|
+
def version
|
111
|
+
puts "Git2GraphViz v#{Constants::RGV_VERSION}, (c)2010 Gregoire Lejeune <gregoire.lejeune@free.fr>"
|
112
|
+
puts ""
|
113
|
+
puts "This program is free software; you can redistribute it and/or modify"
|
114
|
+
puts "it under the terms of the GNU General Public License as published by"
|
115
|
+
puts "the Free Software Foundation; either version 2 of the License, or"
|
116
|
+
puts "(at your option) any later version."
|
117
|
+
puts ""
|
118
|
+
puts "This program is distributed in the hope that it will be useful,"
|
119
|
+
puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
|
120
|
+
puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
|
121
|
+
puts "GNU General Public License for more details."
|
122
|
+
puts ""
|
123
|
+
puts "You should have received a copy of the GNU General Public License"
|
124
|
+
puts "along with this program; if not, write to the Free Software"
|
125
|
+
puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
|
126
|
+
end
|
127
|
+
|
128
|
+
oOpt = GetoptLong.new(
|
129
|
+
['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
|
130
|
+
['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
131
|
+
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
132
|
+
['--nothugly', GetoptLong::NO_ARGUMENT],
|
133
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
134
|
+
['--version', '-V', GetoptLong::NO_ARGUMENT]
|
135
|
+
)
|
136
|
+
|
137
|
+
xOutFormat = "png"
|
138
|
+
xOutFile = nil
|
139
|
+
xGVPath = ""
|
140
|
+
bNothugly = false
|
141
|
+
|
142
|
+
begin
|
143
|
+
oOpt.each_option do |xOpt, xValue|
|
144
|
+
case xOpt
|
145
|
+
when '--output-format'
|
146
|
+
xOutFormat = xValue
|
147
|
+
when '--output-file'
|
148
|
+
xOutFile = xValue
|
149
|
+
when '--path'
|
150
|
+
xGVPath = xValue
|
151
|
+
when '--nothugly'
|
152
|
+
bNothugly = true
|
153
|
+
when '--help'
|
154
|
+
usage( )
|
155
|
+
exit
|
156
|
+
when '--version'
|
157
|
+
version( )
|
158
|
+
exit
|
159
|
+
end
|
160
|
+
end
|
161
|
+
rescue GetoptLong::InvalidOption => e
|
162
|
+
usage( )
|
163
|
+
exit
|
164
|
+
end
|
165
|
+
|
166
|
+
xFile = ARGV[0]
|
167
|
+
|
168
|
+
Git2Gv.new( xGVPath, xOutFile, xOutFormat, bNothugly ).run
|
169
|
+
|
data/examples/dot/hello_test.rb
CHANGED
data/examples/dot/test_parse.rb
CHANGED
data/examples/sample49.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# http://www.graphviz.org/Gallery/directed/hello.html
|
2
|
+
#
|
3
|
+
# digraph G {Hello->World}
|
4
|
+
|
5
|
+
$:.unshift( "../lib" );
|
6
|
+
require "graphviz"
|
7
|
+
|
8
|
+
GraphViz::new( :G, :type => :digraph ) { |g|
|
9
|
+
g.world( :label => "<World" ) << g.hello( :label => "Hello>" )
|
10
|
+
}.output( :svg => "#{$0}.svg" )
|
data/lib/ext/gvpr/dot2ruby.g
CHANGED
@@ -13,6 +13,9 @@
|
|
13
13
|
// You should have received a copy of the GNU General Public License
|
14
14
|
// along with this program; if not, write to the Free Software
|
15
15
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
+
//
|
17
|
+
// Usage :
|
18
|
+
// gvpr -f dot2ruby.g [-a <output type>] <dot script>
|
16
19
|
|
17
20
|
BEGIN {
|
18
21
|
int g_strict; int g_direct;
|
@@ -22,6 +25,13 @@ BEGIN {
|
|
22
25
|
string attr; string attrv;
|
23
26
|
graph_t subgraph; graph_t pgraph;
|
24
27
|
graph_t ofgraph;
|
28
|
+
|
29
|
+
string xOut;
|
30
|
+
if( ARGC == 0 ) {
|
31
|
+
xOut = "_";
|
32
|
+
} else {
|
33
|
+
xOut = tolower(ARGV[0]);
|
34
|
+
}
|
25
35
|
|
26
36
|
printf( "# This code was generated by dot2ruby.g\n\n" );
|
27
37
|
|
@@ -32,6 +42,9 @@ BEGIN {
|
|
32
42
|
out = gsub( out, "'", "" );
|
33
43
|
out = gsub( out, "-", "_" );
|
34
44
|
out = gsub( out, ".", "" );
|
45
|
+
out = gsub( out, "%", "u" );
|
46
|
+
out = gsub( out, "+", "" );
|
47
|
+
out = gsub( out, "/", "_" );
|
35
48
|
return( out );
|
36
49
|
}
|
37
50
|
}
|
@@ -41,9 +54,9 @@ BEG_G {
|
|
41
54
|
// Directed
|
42
55
|
g_direct = isDirect($);
|
43
56
|
if( g_direct == 0 ) {
|
44
|
-
printf( "graph_%s = GraphViz.graph( \"%s\"", rubyfy($.name), $.name );
|
57
|
+
printf( "graph_%s = GraphViz.graph( \"%s\"", rubyfy($.name), rubyfy($.name) );
|
45
58
|
} else {
|
46
|
-
printf( "graph_%s = GraphViz.digraph( \"%s\"", rubyfy($.name), $.name );
|
59
|
+
printf( "graph_%s = GraphViz.digraph( \"%s\"", rubyfy($.name), rubyfy($.name) );
|
47
60
|
}
|
48
61
|
// Strict
|
49
62
|
g_strict = isStrict($);
|
@@ -66,7 +79,7 @@ BEG_G {
|
|
66
79
|
subgraph = fstsubg( $ );
|
67
80
|
while( subgraph != NULL ) {
|
68
81
|
pgraph = subgraph.parent;
|
69
|
-
printf ( " graph_%s = graph_%s.add_graph( \"%s\" )\n", rubyfy(subgraph.name), pgraph.name, subgraph.name );
|
82
|
+
printf ( " graph_%s = graph_%s.add_graph( \"%s\" )\n", rubyfy(subgraph.name), rubyfy(pgraph.name), rubyfy(subgraph.name) );
|
70
83
|
|
71
84
|
// ATTRS
|
72
85
|
attr = fstAttr(subgraph, "G");
|
@@ -142,5 +155,11 @@ E {
|
|
142
155
|
|
143
156
|
END_G {
|
144
157
|
printf( "}\n" );
|
145
|
-
|
158
|
+
if( xOut != "_" ) {
|
159
|
+
if( xOut == "-" ) {
|
160
|
+
printf( "@_graph_eval = graph_%s\n", rubyfy($.name) );
|
161
|
+
} else {
|
162
|
+
printf( "graph_%s.output( :%s => \"%s.%s\" )\n", rubyfy($.name), xOut, gsub($F, ".*/", ""), xOut );
|
163
|
+
}
|
164
|
+
}
|
146
165
|
}
|
data/lib/graphviz.rb
CHANGED
@@ -25,7 +25,11 @@ require 'graphviz/node'
|
|
25
25
|
require 'graphviz/edge'
|
26
26
|
require 'graphviz/attrs'
|
27
27
|
require 'graphviz/constants'
|
28
|
+
|
29
|
+
# --> WILL BE REMOVED
|
28
30
|
require 'graphviz/parser'
|
31
|
+
|
32
|
+
require 'graphviz/dot2ruby'
|
29
33
|
require 'graphviz/types'
|
30
34
|
require 'graphviz/core_ext'
|
31
35
|
|
@@ -389,7 +393,7 @@ class GraphViz
|
|
389
393
|
xDOTScript << "}"
|
390
394
|
|
391
395
|
if @oParentGraph.nil? == false
|
392
|
-
xDOTScript = "subgraph #{@name} {\n" << xDOTScript
|
396
|
+
xDOTScript = "subgraph #{GraphViz.escape(@name)} {\n" << xDOTScript
|
393
397
|
|
394
398
|
return( xDOTScript )
|
395
399
|
else
|
@@ -436,7 +440,7 @@ class GraphViz
|
|
436
440
|
|
437
441
|
@output = hOutput if hOutput.size > 0
|
438
442
|
|
439
|
-
xDOTScript = ("#{@oGraphType} #{@name} {\n" << xDOTScript).gsub( /\0/, "" )
|
443
|
+
xDOTScript = ("#{@oGraphType} #{GraphViz.escape(@name)} {\n" << xDOTScript).gsub( /\0/, "" )
|
440
444
|
|
441
445
|
xOutputString = (@filename == String ||
|
442
446
|
@output.any? {|format, file| file == String })
|
@@ -619,10 +623,34 @@ class GraphViz
|
|
619
623
|
# * :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
|
620
624
|
#
|
621
625
|
def self.parse( xFile, hOpts = {}, &block )
|
626
|
+
# This method will be replaced by parser2.
|
627
|
+
# When it's time, remove
|
628
|
+
# graphviz/parser.rb
|
629
|
+
# graphviz/dot.treetop
|
630
|
+
# and remove line
|
631
|
+
# s.add_dependency('treetop')
|
632
|
+
# in Rakefile
|
622
633
|
g = GraphViz::Parser.parse( xFile, hOpts, &block )
|
623
634
|
return g
|
624
635
|
end
|
625
636
|
|
637
|
+
#
|
638
|
+
# Create a new graph from a GraphViz File
|
639
|
+
#
|
640
|
+
# Options :
|
641
|
+
# * :output : Output format (Constants::FORMATS) (default : dot)
|
642
|
+
# * :file : Output file name (default : none)
|
643
|
+
# * :use : Program to use (Constants::PROGRAMS) (default : dot)
|
644
|
+
# * :path : Program PATH
|
645
|
+
#
|
646
|
+
# <b>WARNING</b> : This method will replace GraphViz.parser. So please use it only for testing...
|
647
|
+
#
|
648
|
+
def self.parse2( xFile, hOpts = {}, &block )
|
649
|
+
graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval( xFile )
|
650
|
+
yield( graph ) if( block and graph.nil? == false )
|
651
|
+
return graph
|
652
|
+
end
|
653
|
+
|
626
654
|
## ----------------------------------------------------------------------------
|
627
655
|
|
628
656
|
private
|
@@ -727,8 +755,7 @@ class GraphViz
|
|
727
755
|
def self.escape(str, force = false ) #:nodoc:
|
728
756
|
if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?
|
729
757
|
'"' + str.gsub('"', '\\"').gsub("\n", '\\\\n').gsub(".","\\.") + '"'
|
730
|
-
|
731
|
-
# '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
|
758
|
+
## MAYBE WE NEED TO USE THIS ONE ## str.inspect.gsub(".","\\.").gsub( "\\\\", "\\" )
|
732
759
|
else
|
733
760
|
str
|
734
761
|
end
|
data/lib/graphviz/constants.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
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 'graphviz/ext'
|
19
|
+
require 'graphviz/utils'
|
20
|
+
|
21
|
+
class Dot2Ruby #:nodoc:
|
22
|
+
include GVUtils
|
23
|
+
|
24
|
+
def initialize( xGVPath, xOutFile, xOutFormat = nil ) #:nodoc:
|
25
|
+
paths = (xGVPath.nil?) ? [] : [xGVPath]
|
26
|
+
@xGvprPath = find_executable( 'gvpr', paths )
|
27
|
+
@xOutFile = xOutFile
|
28
|
+
@xOutFormat = xOutFormat || "_"
|
29
|
+
@gvprScript = GraphViz::Ext.find( "dot2ruby.g" )
|
30
|
+
end
|
31
|
+
|
32
|
+
def run( xFile ) #:nodoc:
|
33
|
+
xCmd = "#{@xGvprPath} -f #{@gvprScript} -a #{@xOutFormat} #{xFile}"
|
34
|
+
xOutput = output_from_command( xCmd )
|
35
|
+
if @xOutFile.nil?
|
36
|
+
puts xOutput
|
37
|
+
else
|
38
|
+
File.open( @xOutFile, "w" ) do |io|
|
39
|
+
io.print xOutput
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def eval( xFile ) #:nodoc:
|
45
|
+
xCmd = "#{@xGvprPath} -f #{@gvprScript} -a \"-\" #{xFile}"
|
46
|
+
xOutput = output_from_command( xCmd )
|
47
|
+
instance_eval(xOutput)
|
48
|
+
return @_graph_eval
|
49
|
+
end
|
50
|
+
end
|
data/test/test_examples.rb
CHANGED
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:
|
4
|
+
hash: 37
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 15
|
10
|
+
version: 0.9.15
|
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-
|
18
|
+
date: 2010-07-19 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,7 @@ executables:
|
|
38
38
|
- ruby2gv
|
39
39
|
- gem2gv
|
40
40
|
- dot2ruby
|
41
|
+
- git2gv
|
41
42
|
extensions: []
|
42
43
|
|
43
44
|
extra_rdoc_files:
|
@@ -51,6 +52,7 @@ files:
|
|
51
52
|
- setup.rb
|
52
53
|
- bin/dot2ruby
|
53
54
|
- bin/gem2gv
|
55
|
+
- bin/git2gv
|
54
56
|
- bin/ruby2gv
|
55
57
|
- examples/dot/balanced.dot
|
56
58
|
- examples/dot/cluster.dot
|
@@ -127,6 +129,7 @@ files:
|
|
127
129
|
- examples/sample53.rb
|
128
130
|
- examples/sample54.rb
|
129
131
|
- examples/sample55.rb
|
132
|
+
- examples/sample56.rb
|
130
133
|
- examples/sample99.rb
|
131
134
|
- examples/sdlshapes/README
|
132
135
|
- examples/sdlshapes/sdl.ps
|
@@ -138,6 +141,7 @@ files:
|
|
138
141
|
- lib/graphviz/constants.rb
|
139
142
|
- lib/graphviz/core_ext.rb
|
140
143
|
- lib/graphviz/dot.treetop
|
144
|
+
- lib/graphviz/dot2ruby.rb
|
141
145
|
- lib/graphviz/edge.rb
|
142
146
|
- lib/graphviz/ext.rb
|
143
147
|
- lib/graphviz/family_tree/couple.rb
|
@@ -160,7 +164,7 @@ files:
|
|
160
164
|
- test/test_examples.rb
|
161
165
|
- test/test_init.rb
|
162
166
|
has_rdoc: true
|
163
|
-
homepage: http://
|
167
|
+
homepage: http://github.com/glejeune/Ruby-Graphviz
|
164
168
|
licenses: []
|
165
169
|
|
166
170
|
post_install_message: |
|