tinydot 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d6b9d99e10dd7f58016497498c2417ad70fd00
4
- data.tar.gz: a27aa25ca0af4e4bed730a63f9a0fbcb7a4334d5
3
+ metadata.gz: 474db36b66a74660fee3b7252e21b28af429dea1
4
+ data.tar.gz: 55e2ed6fb7d9c94457d41ac7d41ba25bd499456e
5
5
  SHA512:
6
- metadata.gz: 19dfe9cb26aeb923392aa1caa272e9db55daadfeda7de9f3a85dbe5fd92738f605105213f1f70eba52f768717e8027867a869e31080da1376b62317ce715c5f7
7
- data.tar.gz: 9ad335ae752f82234030373b6f2947337d5f43f1c859045f61c29a0c50b2461469632ca373bb0653973ba82ec16b97ead4faced402eabeebe49c864661fc842f
6
+ metadata.gz: 62ac5e5552172e8c03c8a9369f18f48ca6aca6b4c4f08cd15f7213f1e15cb7995c89ae44cd683fde28e017cfad2076638bd0827a64e36889c22fdc3ca8898146
7
+ data.tar.gz: 309b2c1f391fae264cecfb4ac2afc54e2495c77cc23f3aba98d444c4e7ed7d441f18d1fde427d60425fe43eddd7d0b946e8569edbafac885e9f6b0e7de372b54
data/README.md CHANGED
@@ -20,6 +20,8 @@ $ tinydot convert sample.tinydot
20
20
 
21
21
  ## Examples
22
22
 
23
+ ### Nodes, Edges
24
+
23
25
  ```rb
24
26
  digraph "sample" do
25
27
  a >> b >> c
@@ -43,3 +45,48 @@ and converted into a following graph.
43
45
 
44
46
  ![sample](examples/sample.png "sample")
45
47
 
48
+ ### Attributes
49
+
50
+ ```rb
51
+ digraph "sample2", rankdir: "LR" do
52
+ node shape: "record", style: "filled", fontname: "Osaka", fillcolor: "#ECF0F1"
53
+
54
+ a "Label 1"
55
+ b "Label 2"
56
+ c "Label 3", fillcolor: "#27AE60"
57
+ d "Label 4", fillcolor: "#F1C40F"
58
+ e "Label 5", fillcolor: "#E74C3C"
59
+
60
+ a <=> b
61
+ a <=> c
62
+ b >> d
63
+ d <=> e
64
+ d >> a
65
+ end
66
+ ```
67
+
68
+ is equivalent to
69
+
70
+ ```dot
71
+ digraph sample2 {
72
+ graph [rankdir = LR];
73
+ node [shape = record, style = filled, fontname = "Osaka", fillcolor = "#ECF0F1"];
74
+
75
+ a [label = "Label 1"];
76
+ b [label = "Label 2"];
77
+ c [label = "Label 3", fillcolor = "#27AE60"];
78
+ d [label = "Label 4", fillcolor = "#F1C40F"];
79
+ e [label = "Label 5", fillcolor = "#E74C3C"];
80
+
81
+ a -> b [dir = both];
82
+ a -> c [dir = both];
83
+ b -> d;
84
+ d -> e [dir = both];
85
+ d -> a;
86
+ }
87
+ ```
88
+
89
+ and converted into a following graph.
90
+
91
+ ![sample2](examples/sample2.png "sample2")
92
+
Binary file
@@ -0,0 +1,15 @@
1
+ digraph "sample2", rankdir: "LR" do
2
+ node shape: "record", style: "filled", fontname: "Osaka", fillcolor: "#ECF0F1"
3
+
4
+ a "Label 1"
5
+ b "Label 2"
6
+ c "Label 3", fillcolor: "#27AE60"
7
+ d "Label 4", fillcolor: "#F1C40F"
8
+ e "Label 5", fillcolor: "#E74C3C"
9
+
10
+ a <=> b
11
+ a <=> c
12
+ b >> d
13
+ d <=> e
14
+ d >> a
15
+ end
@@ -2,9 +2,15 @@ require "erb"
2
2
 
3
3
  module Tinydot
4
4
  class Digraph
5
- def initialize(name)
5
+ def initialize(name, attrs = {})
6
6
  @name = name
7
+ @attrs = attrs
7
8
  @nodes = []
9
+ @node_attrs = {}
10
+ end
11
+
12
+ def node(attrs = {})
13
+ @node_attrs = attrs
8
14
  end
9
15
 
10
16
  def to_dot
@@ -16,10 +22,34 @@ module Tinydot
16
22
  def method_missing(name, *args)
17
23
  node = @nodes.select { |node| node.name == name }.first
18
24
  if node.nil?
19
- node = Node.new(name)
25
+ attrs = {}
26
+ args.each do |arg|
27
+ case arg
28
+ when String then attrs[:label] = arg
29
+ when Hash then attrs.merge!(arg)
30
+ end
31
+ end
32
+
33
+ node = Node.new(name, attrs)
20
34
  @nodes << node
21
35
  end
22
36
  node
23
37
  end
38
+
39
+ private
40
+
41
+ def attrs_to_dot
42
+ quoted_attrs = %i(size label bgcolor fillcolor fontname)
43
+ @attrs.map do |k, v|
44
+ quoted_attrs.include?(k) ? %(#{k} = "#{v}") : %(#{k} = #{v})
45
+ end.join(", ")
46
+ end
47
+
48
+ def node_attrs_to_dot
49
+ quoted_attrs = %i(color fillcolor fillcolor fontname)
50
+ @node_attrs.map do |k, v|
51
+ quoted_attrs.include?(k) ? %(#{k} = "#{v}") : %(#{k} = #{v})
52
+ end.join(", ")
53
+ end
24
54
  end
25
55
  end
data/lib/tinydot/node.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module Tinydot
2
2
  class Node
3
- attr_reader :name, :edges
3
+ attr_reader :name, :edges, :attrs
4
4
 
5
- def initialize(name)
5
+ def initialize(name, attrs)
6
6
  @name = name
7
7
  @edges = []
8
+ @attrs = attrs || {}
8
9
  end
9
10
 
10
11
  def >>(other)
@@ -16,5 +17,12 @@ module Tinydot
16
17
  @edges << Edge.new(self, other, dir: "both")
17
18
  other
18
19
  end
20
+
21
+ def to_dot
22
+ quoted_attrs = %i(label color fillcolor fontname)
23
+ @attrs.map do |k, v|
24
+ quoted_attrs.include?(k) ? %(#{k} = "#{v}") : %(#{k} = #{v})
25
+ end.join(", ")
26
+ end
19
27
  end
20
28
  end
@@ -6,8 +6,8 @@ module Tinydot
6
6
  graph.to_dot
7
7
  end
8
8
 
9
- def digraph(title, &block)
10
- digraph = Digraph.new(title)
9
+ def digraph(title, attrs = {}, &block)
10
+ digraph = Digraph.new(title, attrs)
11
11
  digraph.instance_eval(&block)
12
12
  digraph
13
13
  end
@@ -1,4 +1,19 @@
1
1
  digraph <%= @name %> {
2
+ <%- unless @attrs.empty? -%>
3
+ <%= "graph [#{attrs_to_dot}];" %>
4
+ <%- end -%>
5
+ <%- unless @node_attrs.empty? -%>
6
+ <%= "node [#{node_attrs_to_dot}];" %>
7
+ <%- end -%>
8
+ <%- if !(@attrs.empty? && @node_attrs.empty?) -%>
9
+
10
+ <%- end -%>
11
+ <%- @nodes.select { |node| !node.attrs.empty? }.each do |node| -%>
12
+ <%= "#{node.name} [#{node.to_dot}];" %>
13
+ <%- end -%>
14
+ <%- if !@nodes.select { |node| !node.attrs.empty? }.empty? -%>
15
+
16
+ <%- end -%>
2
17
  <%- @nodes.each do |node| -%>
3
18
  <%- node.edges.each do |edge| -%>
4
19
  <%= edge.to_dot %>
@@ -0,0 +1,6 @@
1
+ digraph sample {
2
+ node [shape = box, fontname = "Osaka", style = styled, fillcolor = "#ECF0F1"];
3
+
4
+ a -> b;
5
+ b -> c;
6
+ }
@@ -0,0 +1,4 @@
1
+ digraph "sample" do
2
+ node shape: "box", fontname: "Osaka", style: "styled", fillcolor: "#ECF0F1"
3
+ a >> b >> c
4
+ end
@@ -0,0 +1,6 @@
1
+ digraph sample {
2
+ graph [rankdir = LR];
3
+
4
+ a -> b;
5
+ b -> c;
6
+ }
@@ -0,0 +1,3 @@
1
+ digraph "sample", rankdir: "LR" do
2
+ a >> b >> c
3
+ end
@@ -0,0 +1,8 @@
1
+ digraph sample {
2
+ a [label = "index.html"];
3
+ b [label = "show.html"];
4
+ c [label = "new.html", fillcolor = "#E74C3C"];
5
+
6
+ a -> b [dir = both];
7
+ a -> c;
8
+ }
@@ -0,0 +1,8 @@
1
+ digraph "sample" do
2
+ a "index.html"
3
+ b "show.html"
4
+ c "new.html", fillcolor: "#E74C3C"
5
+
6
+ a <=> b
7
+ a >> c
8
+ end
@@ -14,4 +14,22 @@ describe Tinydot::Parser do
14
14
  dot = Tinydot::Parser.parse(tinydot)
15
15
  expect(dot).to eq fixtures_path.join("bidirectional_edge.dot").read
16
16
  end
17
+
18
+ it "parses attributes of digraph" do
19
+ tinydot = fixtures_path.join("digraph_attributes.tinydot").read
20
+ dot = Tinydot::Parser.parse(tinydot)
21
+ expect(dot).to eq fixtures_path.join("digraph_attributes.dot").read
22
+ end
23
+
24
+ it "parses attributes of all nodes" do
25
+ tinydot = fixtures_path.join("all_nodes_attributes.tinydot").read
26
+ dot = Tinydot::Parser.parse(tinydot)
27
+ expect(dot).to eq fixtures_path.join("all_nodes_attributes.dot").read
28
+ end
29
+
30
+ it "parses attributes of each node" do
31
+ tinydot = fixtures_path.join("node_attributes.tinydot").read
32
+ dot = Tinydot::Parser.parse(tinydot)
33
+ expect(dot).to eq fixtures_path.join("node_attributes.dot").read
34
+ end
17
35
  end
data/tinydot.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "tinydot"
6
- spec.version = "0.0.1"
6
+ spec.version = "0.0.2"
7
7
  spec.authors = ["Naoto Kaneko"]
8
8
  spec.email = ["naoty.k@gmail.com"]
9
9
  spec.summary = %q{Tiny language alternative to DOT.}
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinydot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Kaneko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.18.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.18.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.14.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.14.1
69
69
  description:
@@ -74,7 +74,7 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".gitignore"
77
+ - .gitignore
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
@@ -82,6 +82,8 @@ files:
82
82
  - bin/tinydot
83
83
  - examples/sample.png
84
84
  - examples/sample.tinydot
85
+ - examples/sample2.png
86
+ - examples/sample2.tinydot
85
87
  - lib/tinydot.rb
86
88
  - lib/tinydot/command.rb
87
89
  - lib/tinydot/digraph.rb
@@ -89,8 +91,14 @@ files:
89
91
  - lib/tinydot/node.rb
90
92
  - lib/tinydot/parser.rb
91
93
  - lib/tinydot/template.dot.erb
94
+ - spec/fixtures/all_nodes_attributes.dot
95
+ - spec/fixtures/all_nodes_attributes.tinydot
92
96
  - spec/fixtures/bidirectional_edge.dot
93
97
  - spec/fixtures/bidirectional_edge.tinydot
98
+ - spec/fixtures/digraph_attributes.dot
99
+ - spec/fixtures/digraph_attributes.tinydot
100
+ - spec/fixtures/node_attributes.dot
101
+ - spec/fixtures/node_attributes.tinydot
94
102
  - spec/fixtures/unidirectional_edges.dot
95
103
  - spec/fixtures/unidirectional_edges.tinydot
96
104
  - spec/spec_helper.rb
@@ -106,23 +114,29 @@ require_paths:
106
114
  - lib
107
115
  required_ruby_version: !ruby/object:Gem::Requirement
108
116
  requirements:
109
- - - ">="
117
+ - - '>='
110
118
  - !ruby/object:Gem::Version
111
119
  version: '0'
112
120
  required_rubygems_version: !ruby/object:Gem::Requirement
113
121
  requirements:
114
- - - ">="
122
+ - - '>='
115
123
  - !ruby/object:Gem::Version
116
124
  version: '0'
117
125
  requirements: []
118
126
  rubyforge_project:
119
- rubygems_version: 2.2.0
127
+ rubygems_version: 2.0.14
120
128
  signing_key:
121
129
  specification_version: 4
122
130
  summary: Tiny language alternative to DOT.
123
131
  test_files:
132
+ - spec/fixtures/all_nodes_attributes.dot
133
+ - spec/fixtures/all_nodes_attributes.tinydot
124
134
  - spec/fixtures/bidirectional_edge.dot
125
135
  - spec/fixtures/bidirectional_edge.tinydot
136
+ - spec/fixtures/digraph_attributes.dot
137
+ - spec/fixtures/digraph_attributes.tinydot
138
+ - spec/fixtures/node_attributes.dot
139
+ - spec/fixtures/node_attributes.tinydot
126
140
  - spec/fixtures/unidirectional_edges.dot
127
141
  - spec/fixtures/unidirectional_edges.tinydot
128
142
  - spec/spec_helper.rb