tinydot 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50d6b9d99e10dd7f58016497498c2417ad70fd00
4
+ data.tar.gz: a27aa25ca0af4e4bed730a63f9a0fbcb7a4334d5
5
+ SHA512:
6
+ metadata.gz: 19dfe9cb26aeb923392aa1caa272e9db55daadfeda7de9f3a85dbe5fd92738f605105213f1f70eba52f768717e8027867a869e31080da1376b62317ce715c5f7
7
+ data.tar.gz: 9ad335ae752f82234030373b6f2947337d5f43f1c859045f61c29a0c50b2461469632ca373bb0653973ba82ec16b97ead4faced402eabeebe49c864661fc842f
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rspec
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tinydot.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naoto Kaneko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Tinydot
2
+
3
+ Tiny language alternative to DOT.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ gem install tinydot
9
+ ```
10
+
11
+ [Graphviz](http://www.graphviz.org/) is required to convert files written by tinydot into images.
12
+
13
+ ## Usage
14
+
15
+ ```sh
16
+ $ tinydot convert sample.tinydot
17
+ ```
18
+
19
+ `tinydot` command converts `*.tinydot` or `*.tdot` into `*.dot` and converts the converted files into graph images using Graphviz.
20
+
21
+ ## Examples
22
+
23
+ ```rb
24
+ digraph "sample" do
25
+ a >> b >> c
26
+ a <=> d
27
+ b <=> d
28
+ end
29
+ ```
30
+
31
+ is equivalent to
32
+
33
+ ```dot
34
+ digraph sample {
35
+ a -> b;
36
+ b -> c;
37
+ a -> d [dir = both];
38
+ b -> d [dir = both];
39
+ }
40
+ ```
41
+
42
+ and converted into a following graph.
43
+
44
+ ![sample](examples/sample.png "sample")
45
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/tinydot ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "tinydot"
4
+ Tinydot::Command.start(ARGV)
Binary file
@@ -0,0 +1,5 @@
1
+ digraph "sample" do
2
+ a >> b >> c
3
+ a <=> d
4
+ b <=> d
5
+ end
@@ -0,0 +1,24 @@
1
+ require "thor"
2
+
3
+ module Tinydot
4
+ class Command < Thor
5
+ desc "convert <source>", "Convert tinydot file into graph image"
6
+ def convert(source)
7
+ source_path = Pathname.new(source)
8
+ unless %w(.tinydot .tdot).include?(source_path.extname)
9
+ abort "source must be *.tinydot or *.tdot"
10
+ end
11
+
12
+ target_name = source_path.to_s.gsub(/\.(tinydot|tdot)$/) { "" }
13
+ target_dot_path = Pathname.new("#{target_name}.dot")
14
+ target_image_path = Pathname.new("#{target_name}.png")
15
+ File.open(source, "rb") do |file|
16
+ tinydot = file.read
17
+ dot = Parser.parse(tinydot)
18
+ target_dot_path.open("wb") { |file| file.write(dot) }
19
+ system %(dot -Tpng -o #{target_image_path.to_s} #{target_dot_path.to_s})
20
+ target_dot_path.delete
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require "erb"
2
+
3
+ module Tinydot
4
+ class Digraph
5
+ def initialize(name)
6
+ @name = name
7
+ @nodes = []
8
+ end
9
+
10
+ def to_dot
11
+ template_path = Tinydot.root_path.join("lib/tinydot/template.dot.erb")
12
+ template = ERB.new(template_path.read, nil, "-")
13
+ template.result(binding)
14
+ end
15
+
16
+ def method_missing(name, *args)
17
+ node = @nodes.select { |node| node.name == name }.first
18
+ if node.nil?
19
+ node = Node.new(name)
20
+ @nodes << node
21
+ end
22
+ node
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Tinydot
2
+ class Edge
3
+ def initialize(from, to, attrs = {})
4
+ @from = from
5
+ @to = to
6
+ @attrs = attrs
7
+ end
8
+
9
+ def to_dot
10
+ dot = "#{@from.name} -> #{@to.name}"
11
+ dot += " [dir = both]" if @attrs[:dir] == "both"
12
+ dot += ";"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Tinydot
2
+ class Node
3
+ attr_reader :name, :edges
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @edges = []
8
+ end
9
+
10
+ def >>(other)
11
+ @edges << Edge.new(self, other)
12
+ other
13
+ end
14
+
15
+ def <=>(other)
16
+ @edges << Edge.new(self, other, dir: "both")
17
+ other
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module Tinydot
2
+ class Parser
3
+ def self.parse(content)
4
+ parser = Parser.new
5
+ graph = parser.instance_eval(content)
6
+ graph.to_dot
7
+ end
8
+
9
+ def digraph(title, &block)
10
+ digraph = Digraph.new(title)
11
+ digraph.instance_eval(&block)
12
+ digraph
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ digraph <%= @name %> {
2
+ <%- @nodes.each do |node| -%>
3
+ <%- node.edges.each do |edge| -%>
4
+ <%= edge.to_dot %>
5
+ <%- end -%>
6
+ <%- end -%>
7
+ }
data/lib/tinydot.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "tinydot/command"
2
+ require "tinydot/parser"
3
+ require "tinydot/digraph"
4
+ require "tinydot/node"
5
+ require "tinydot/edge"
6
+
7
+ require "pathname"
8
+
9
+ module Tinydot
10
+ def self.root_path
11
+ Pathname.new("..").expand_path(File.dirname(__FILE__))
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ digraph sample {
2
+ a -> b [dir = both];
3
+ }
@@ -0,0 +1,3 @@
1
+ digraph "sample" do
2
+ a <=> b
3
+ end
@@ -0,0 +1,4 @@
1
+ digraph sample {
2
+ a -> b;
3
+ b -> c;
4
+ }
@@ -0,0 +1,3 @@
1
+ digraph "sample" do
2
+ a >> b >> c
3
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path("../lib/tinydot", File.dirname(__FILE__))
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.order = "random"
6
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Tinydot::Parser do
4
+ let(:fixtures_path) { Pathname.new("spec/fixtures") }
5
+
6
+ it "parses a series of unidirectional edges" do
7
+ tinydot = fixtures_path.join("unidirectional_edges.tinydot").read
8
+ dot = Tinydot::Parser.parse(tinydot)
9
+ expect(dot).to eq fixtures_path.join("unidirectional_edges.dot").read
10
+ end
11
+
12
+ it "parses a bidirectional edge" do
13
+ tinydot = fixtures_path.join("bidirectional_edge.tinydot").read
14
+ dot = Tinydot::Parser.parse(tinydot)
15
+ expect(dot).to eq fixtures_path.join("bidirectional_edge.dot").read
16
+ end
17
+ end
data/tinydot.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "tinydot"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Naoto Kaneko"]
8
+ spec.email = ["naoty.k@gmail.com"]
9
+ spec.summary = %q{Tiny language alternative to DOT.}
10
+ spec.homepage = "https://github.com/naoty/tinydot"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "thor", "~> 0.18.1"
19
+ spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", "~> 2.14.1"
22
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinydot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naoto Kaneko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ description:
70
+ email:
71
+ - naoty.k@gmail.com
72
+ executables:
73
+ - tinydot
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/tinydot
83
+ - examples/sample.png
84
+ - examples/sample.tinydot
85
+ - lib/tinydot.rb
86
+ - lib/tinydot/command.rb
87
+ - lib/tinydot/digraph.rb
88
+ - lib/tinydot/edge.rb
89
+ - lib/tinydot/node.rb
90
+ - lib/tinydot/parser.rb
91
+ - lib/tinydot/template.dot.erb
92
+ - spec/fixtures/bidirectional_edge.dot
93
+ - spec/fixtures/bidirectional_edge.tinydot
94
+ - spec/fixtures/unidirectional_edges.dot
95
+ - spec/fixtures/unidirectional_edges.tinydot
96
+ - spec/spec_helper.rb
97
+ - spec/tinydot/parser_spec.rb
98
+ - tinydot.gemspec
99
+ homepage: https://github.com/naoty/tinydot
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.0
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Tiny language alternative to DOT.
123
+ test_files:
124
+ - spec/fixtures/bidirectional_edge.dot
125
+ - spec/fixtures/bidirectional_edge.tinydot
126
+ - spec/fixtures/unidirectional_edges.dot
127
+ - spec/fixtures/unidirectional_edges.tinydot
128
+ - spec/spec_helper.rb
129
+ - spec/tinydot/parser_spec.rb