gviz 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/bin/gviz +1 -88
- data/gviz.gemspec +1 -1
- data/lib/gviz.rb +1 -1
- data/lib/gviz/command.rb +76 -0
- data/lib/gviz/core.rb +1 -1
- data/lib/gviz/version.rb +1 -1
- data/spec/{graph.ru → fixtures/graph.ru} +0 -0
- data/spec/gviz_command_spec.rb +92 -69
- data/spec/spec_helper.rb +8 -4
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9143e573c91a80a888a66007403500d36f5406dc
|
4
|
+
data.tar.gz: d8512ead6616fd21edd84d61730ec0c70af97682
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c9af9c343b65c8d03669d4b604934fcbb3c0e65a88f2da3701be27f87acc2a199bcdb83237cdb6492736c419661438d5157a50e63d9349d6ec81622102e9586
|
7
|
+
data.tar.gz: cf4ee9d30253268b5c6115491ec7f2f136f89f5d82667cfbd41e69b3d06ba13da4e7c8ecbd5547b32767142cbb05365ed1d4e6af4b950da0445b27bf338b17fb
|
data/README.md
CHANGED
@@ -118,14 +118,12 @@ Example of graph.ru:
|
|
118
118
|
|
119
119
|
Usage:
|
120
120
|
|
121
|
-
gviz [options]
|
121
|
+
gviz build [FILE] [options]
|
122
122
|
|
123
123
|
where [options] are:
|
124
124
|
|
125
125
|
--name, -n : Graph name (default: G)
|
126
126
|
--type, -t : Graph type (default: digraph)
|
127
|
-
--version, -v: Print version and exit
|
128
|
-
--help, -h: Show this message
|
129
127
|
|
130
128
|
## Contributing
|
131
129
|
|
data/bin/gviz
CHANGED
@@ -1,91 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "gviz"
|
3
|
-
require "trollop"
|
4
3
|
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def parse!
|
8
|
-
opts = build_opts
|
9
|
-
if man = opts[:man]
|
10
|
-
print_manual(man)
|
11
|
-
else
|
12
|
-
draw_graph(opts)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def build_opts
|
17
|
-
Trollop::options do
|
18
|
-
version "Gviz #{Gviz::VERSION} (c) 2012 kyoendo"
|
19
|
-
banner ~<<-EOS
|
20
|
-
Gviz is a tool for generating graphviz dot data with simple Ruby's syntax.
|
21
|
-
It works with a graph spec file in which a graph spec describes with
|
22
|
-
several gviz commands. If 'graph.ru' file exist on a directory of the
|
23
|
-
execution, it will be automatically loaded as a graph spec file.
|
24
|
-
|
25
|
-
Example of graph.ru:
|
26
|
-
|
27
|
-
route :main => [:init, :parse, :cleanup, :printf]
|
28
|
-
route :init => :make, :parse => :execute
|
29
|
-
route :execute => [:make, :compare, :printf]
|
30
|
-
|
31
|
-
save(:sample, :png)
|
32
|
-
|
33
|
-
Usage:
|
34
|
-
|
35
|
-
gviz [options] <graph filename>
|
36
|
-
|
37
|
-
where [options] are:
|
38
|
-
EOS
|
39
|
-
|
40
|
-
opt :name, "Graph name", :default => 'G'
|
41
|
-
opt :type, "Graph type", :default => 'digraph'
|
42
|
-
opt :file, "Graph file", :default => 'graph.ru'
|
43
|
-
opt :man, "Show Graphviz attributes (ex. node, shapes, color_names)", :type => :string
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def draw_graph(opts)
|
48
|
-
Graph(opts[:name], opts[:type]) { instance_eval ::File.read(opts[:file]) }
|
49
|
-
rescue Errno::ENOENT
|
50
|
-
abort "graph file `#{opts[:file]}` not found"
|
51
|
-
end
|
52
|
-
|
53
|
-
def print_manual(man)
|
54
|
-
attrs = %w(graph node edge subgraph cluster)
|
55
|
-
consts = %w(color_names color_schemes full_color_names
|
56
|
-
full_color_schemes arrows shapes layouts
|
57
|
-
output_formats svg_color_names dark_colors)
|
58
|
-
man_man = ~<<-EOS
|
59
|
-
\e[35m--man(-m) accepts any of them:\e[0m
|
60
|
-
graph, node, edge, subgraph, cluster,
|
61
|
-
arrows, shapes, layouts, output_formats
|
62
|
-
color_names, color_schemes,
|
63
|
-
full_color_names, full_color_schemes,
|
64
|
-
svg_color_names, dark_colors
|
65
|
-
EOS
|
66
|
-
|
67
|
-
res =
|
68
|
-
case man.downcase
|
69
|
-
when 'man'
|
70
|
-
man_man
|
71
|
-
when *attrs
|
72
|
-
format_attrs(man)
|
73
|
-
when *consts
|
74
|
-
["\e[35m#{man.capitalize.gsub('_', ' ')}:\e[0m"] +
|
75
|
-
Gviz.const_get(man.upcase).join_by(", ", 70).map { |l| " " + l }
|
76
|
-
else
|
77
|
-
"Error: unknown subcommand '#{man}' for --man\n" + man_man
|
78
|
-
end
|
79
|
-
puts res
|
80
|
-
end
|
81
|
-
|
82
|
-
def format_attrs(target)
|
83
|
-
header = ["\e[35m#{target.capitalize} attributes (type|default|minimum|notes):\e[0m"]
|
84
|
-
attrs = Gviz.ATTR(target).map { |attr, desc| " #{attr} (#{desc.join(" | ")})" }
|
85
|
-
[header] + attrs
|
86
|
-
end
|
87
|
-
end
|
88
|
-
private_class_method :build_opts, :draw_graph, :print_manual, :format_attrs
|
89
|
-
end
|
90
|
-
|
91
|
-
OptionParser.parse!
|
4
|
+
Gviz::Command.start(ARGV)
|
data/gviz.gemspec
CHANGED
data/lib/gviz.rb
CHANGED
@@ -7,6 +7,6 @@ def Graph(name=:G, type=:digraph, &blk)
|
|
7
7
|
Gviz.new(name, type).graph(&blk)
|
8
8
|
end
|
9
9
|
|
10
|
-
%w(core node edge version system_extension graphviz_attrs).each do |lib|
|
10
|
+
%w(core node edge version system_extension graphviz_attrs command).each do |lib|
|
11
11
|
require_relative 'gviz/' + lib
|
12
12
|
end
|
data/lib/gviz/command.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
class Gviz::Command < Thor
|
4
|
+
|
5
|
+
desc "build [FILE]", "Build a graphviz dot data based on a file"
|
6
|
+
option :name, aliases:"-n", default:"G"
|
7
|
+
option :type, aliases:"-t", default:"digraph"
|
8
|
+
def build(file='graph.ru')
|
9
|
+
Graph(options[:name], options[:type]) { instance_eval ::File.read(file) }
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
abort "graph file `#{file}` not found"
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "version", "Show Gviz version"
|
15
|
+
def version
|
16
|
+
puts "Gviz #{Gviz::VERSION} (c) 2012-2013 kyoendo"
|
17
|
+
end
|
18
|
+
map "-v" => :version
|
19
|
+
|
20
|
+
desc "banner", "Describe Gviz usage", hide:true
|
21
|
+
def banner
|
22
|
+
banner = ~<<-EOS
|
23
|
+
Gviz is a tool for generating graphviz dot data with simple Ruby's syntax.
|
24
|
+
It works with a graph spec file (defaulting to load 'graph.ru').
|
25
|
+
|
26
|
+
Example of graph.ru:
|
27
|
+
|
28
|
+
route :main => [:init, :parse, :cleanup, :printf]
|
29
|
+
route :init => :make, :parse => :execute
|
30
|
+
route :execute => [:make, :compare, :printf]
|
31
|
+
|
32
|
+
save(:sample, :png)
|
33
|
+
|
34
|
+
EOS
|
35
|
+
puts banner
|
36
|
+
help
|
37
|
+
end
|
38
|
+
default_task :banner
|
39
|
+
map "-h" => :banner
|
40
|
+
|
41
|
+
desc "man [NAME]", "Show available attributes, constants, colors for graphviz"
|
42
|
+
def man(name='')
|
43
|
+
attrs = %w(graph node edge subgraph cluster)
|
44
|
+
consts = %w(arrows shapes layouts output_formats)
|
45
|
+
colors = %w(color_names color_schemes full_color_names
|
46
|
+
full_color_schemes svg_color_names dark_colors)
|
47
|
+
name = name.downcase
|
48
|
+
case name
|
49
|
+
when *attrs then puts format_attr(name)
|
50
|
+
when *consts then puts consts.map { |c| format_const c }
|
51
|
+
when *colors then puts format_const(name)
|
52
|
+
when /color/ then puts colors.map { |c| format_const c }
|
53
|
+
else
|
54
|
+
puts ~<<-EOS
|
55
|
+
Specify any of:
|
56
|
+
#{attrs.join(', ')}
|
57
|
+
#{consts.join(', ')}
|
58
|
+
#{colors.join(', ')}
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
no_commands do
|
64
|
+
def format_attr(target)
|
65
|
+
header = ["\e[35m#{target.capitalize} attributes (type|default|minimum|notes):\e[0m"]
|
66
|
+
attrs = Gviz.ATTR(target).map { |attr, desc| " #{attr} (#{desc.join(" | ")})" }
|
67
|
+
[header] + attrs
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_const(target)
|
71
|
+
header = ["\e[35m#{target.capitalize.gsub('_', ' ')}:\e[0m"]
|
72
|
+
consts = Gviz.const_get(target.upcase).join_by(", ", 70).map { |l| " " + l }
|
73
|
+
[header] + consts
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/gviz/core.rb
CHANGED
data/lib/gviz/version.rb
CHANGED
File without changes
|
data/spec/gviz_command_spec.rb
CHANGED
@@ -1,89 +1,112 @@
|
|
1
1
|
require_relative "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it do
|
9
|
-
should eql ~<<-EOS
|
10
|
-
digraph G {
|
11
|
-
a;
|
12
|
-
b;
|
13
|
-
a -> b;
|
14
|
-
}
|
15
|
-
EOS
|
16
|
-
end
|
3
|
+
describe Gviz::Command do
|
4
|
+
before(:each) do
|
5
|
+
$stdout, $stderr = StringIO.new, StringIO.new
|
6
|
+
@original_dir = Dir.pwd
|
7
|
+
Dir.chdir(source_root)
|
17
8
|
end
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
after(:each) do
|
11
|
+
$stdout, $stderr = STDOUT, STDERR
|
12
|
+
Dir.chdir(@original_dir)
|
22
13
|
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
describe '#build' do
|
16
|
+
context 'with a graph file' do
|
17
|
+
it 'output a dot data' do
|
18
|
+
Gviz::Command.start(['build', 'graph.ru'])
|
19
|
+
expect($stdout.string).to eq ~<<-EOS
|
20
|
+
digraph G {
|
21
|
+
a;
|
22
|
+
b;
|
23
|
+
a -> b;
|
24
|
+
}
|
33
25
|
EOS
|
26
|
+
end
|
34
27
|
end
|
35
|
-
end
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
context 'without a graph file' do
|
30
|
+
it 'read "graph.ru" as a graph file' do
|
31
|
+
Gviz::Command.start(['build'])
|
32
|
+
expect($stdout.string).to eq ~<<-EOS
|
33
|
+
digraph G {
|
34
|
+
a;
|
35
|
+
b;
|
36
|
+
a -> b;
|
37
|
+
}
|
46
38
|
EOS
|
39
|
+
end
|
47
40
|
end
|
48
|
-
end
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
box, lbox, rbox, obox, olbox, orbox, crow, lcrow, rcrow, diamond, ldiamond, rdiamond
|
56
|
-
oldiamond, ordiamond, dot, odot, inv, linv, rinv, oinv, olinv, orinv, none, normal, lnormal
|
57
|
-
EOS
|
42
|
+
context 'when no graph file found' do
|
43
|
+
it 'abort the process' do
|
44
|
+
file = "no_existing_file"
|
45
|
+
expect{ Gviz::Command.start(['build', file]) }.to raise_error(SystemExit, "graph file `#{file}` not found")
|
46
|
+
end
|
58
47
|
end
|
59
|
-
end
|
60
48
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
49
|
+
context "name option" do
|
50
|
+
it 'set a graph name' do
|
51
|
+
Gviz::Command.start(['build', '--name', 'ABC'])
|
52
|
+
expect($stdout.string).to eq ~<<-EOS
|
53
|
+
digraph ABC {
|
54
|
+
a;
|
55
|
+
b;
|
56
|
+
a -> b;
|
57
|
+
}
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "type option" do
|
63
|
+
it 'set a graph type' do
|
64
|
+
Gviz::Command.start(['build', '--type', 'graph'])
|
65
|
+
expect($stdout.string).to eq ~<<-EOS
|
66
|
+
graph G {
|
67
|
+
a;
|
68
|
+
b;
|
69
|
+
a -> b;
|
70
|
+
}
|
71
|
+
EOS
|
72
|
+
end
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
76
|
+
describe '#man' do
|
77
|
+
it 'shows arguments list without argument' do
|
78
|
+
Gviz::Command.start(['man'])
|
79
|
+
expect($stdout.string).to match /Specify any of/
|
80
|
+
end
|
81
|
+
|
82
|
+
it "shows Graph's attributes" do
|
83
|
+
Gviz::Command.start(['man', 'graph'])
|
84
|
+
expect($stdout.string).to match /Graph attributes/
|
85
|
+
end
|
86
|
+
|
87
|
+
it "shows Node's attributes" do
|
88
|
+
Gviz::Command.start(['man', 'node'])
|
89
|
+
expect($stdout.string).to match /Node attributes/
|
90
|
+
end
|
91
|
+
|
92
|
+
it "shows Arrow types" do
|
93
|
+
Gviz::Command.start(['man', 'arrows'])
|
94
|
+
expect($stdout.string).to match /Arrows/
|
95
|
+
end
|
96
|
+
|
97
|
+
it "shows Output formats" do
|
98
|
+
Gviz::Command.start(['man', 'output_formats'])
|
99
|
+
expect($stdout.string).to match /Output formats/
|
100
|
+
end
|
101
|
+
|
102
|
+
it "shows Color names" do
|
103
|
+
Gviz::Command.start(['man', 'color_names'])
|
104
|
+
expect($stdout.string).to match /Color names/
|
105
|
+
end
|
106
|
+
|
107
|
+
it "shows Colors" do
|
108
|
+
Gviz::Command.start(['man', 'colors'])
|
109
|
+
expect($stdout.string).to match /Color/
|
87
110
|
end
|
88
111
|
end
|
89
112
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require "gviz"
|
2
2
|
require "rspec"
|
3
3
|
require "stringio"
|
4
|
-
require "open3"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Helpers
|
6
|
+
def source_root
|
7
|
+
File.join(File.dirname(__FILE__), 'fixtures')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.include Helpers
|
9
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gviz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
@@ -61,13 +61,14 @@ files:
|
|
61
61
|
- examples/shapes.rb
|
62
62
|
- gviz.gemspec
|
63
63
|
- lib/gviz.rb
|
64
|
+
- lib/gviz/command.rb
|
64
65
|
- lib/gviz/core.rb
|
65
66
|
- lib/gviz/edge.rb
|
66
67
|
- lib/gviz/graphviz_attrs.rb
|
67
68
|
- lib/gviz/node.rb
|
68
69
|
- lib/gviz/system_extension.rb
|
69
70
|
- lib/gviz/version.rb
|
70
|
-
- spec/graph.ru
|
71
|
+
- spec/fixtures/graph.ru
|
71
72
|
- spec/gviz_command_spec.rb
|
72
73
|
- spec/gviz_edge_spec.rb
|
73
74
|
- spec/gviz_node_spec.rb
|
@@ -98,10 +99,11 @@ signing_key:
|
|
98
99
|
specification_version: 4
|
99
100
|
summary: Ruby's interface of graphviz. It generate a dot file with simple ruby's syntax.
|
100
101
|
test_files:
|
101
|
-
- spec/graph.ru
|
102
|
+
- spec/fixtures/graph.ru
|
102
103
|
- spec/gviz_command_spec.rb
|
103
104
|
- spec/gviz_edge_spec.rb
|
104
105
|
- spec/gviz_node_spec.rb
|
105
106
|
- spec/gviz_spec.rb
|
106
107
|
- spec/spec_helper.rb
|
107
108
|
- spec/system_extension_spec.rb
|
109
|
+
has_rdoc:
|