dothtml 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +20 -2
- data/README.md +24 -23
- data/dothtml.gemspec +15 -4
- data/exe/dothtml +8 -0
- data/lib/dothtml.rb +2 -2
- data/lib/dothtml/cli.rb +129 -0
- data/lib/dothtml/dot_helper.rb +53 -23
- data/lib/dothtml/dot_task.rb +78 -50
- data/lib/dothtml/version.rb +1 -1
- data/templates/Guardfile +9 -5
- data/templates/sample.dot +13 -0
- data/test/test_dot_helper.rb +0 -40
- metadata +58 -10
- data/bin/dothtml +0 -3
- data/templates/Gemfile +0 -5
- data/templates/Rakefile +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b54d4c5977dab60f40ee0b8452e82d12da98864
|
4
|
+
data.tar.gz: fb18ac649d3d42f8b104e449661d5026f7b17f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3767faa96b216468fa59661e58e52e51bb67c3727c57250205705e6c399d8d9733e4d5a3caa1286afd5b226f905ead7c3ef727c1ebc948b1136a15e541036d50
|
7
|
+
data.tar.gz: de96d861ff797facd40668c3ca8881484461ce46fff95cdf4d7edf7700e98ccb1b66ecdd3d69d29d14e86fe2c77d3dfcec8bc1d6404aa0c7cf3076756aa2a372
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
##
|
3
|
+
## [Unreleased]
|
4
|
+
|
5
|
+
|
6
|
+
## [0.1.0] - 2016-02-09
|
7
|
+
### Added
|
8
|
+
- Rewritten CLI that supports subcommands build, create, and watch
|
9
|
+
- Detect/Add presence of outer `graph {}`
|
10
|
+
- Added minimal layout detection (neato vs dot)
|
11
|
+
- Added support for arbitrary cdn value
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
- Removed merging of id and class as class attribute is now supported by graphviz.
|
15
|
+
|
16
|
+
## [0.0.3] - 2014-12-23
|
4
17
|
### Added
|
5
18
|
- Rule to generate an svg file
|
6
19
|
|
7
|
-
## 0.0.2 - 2014-12-10
|
20
|
+
## [0.0.2] - 2014-12-10
|
8
21
|
### Added
|
9
22
|
- This CHANGELOG
|
10
23
|
- Added behavior and style files. (no longer in template file)
|
@@ -22,3 +35,8 @@
|
|
22
35
|
### Remove
|
23
36
|
- Removed embedding of svg images. Not ready for prime time yet.
|
24
37
|
- Removed requirement on liquid gem. Default template now in erb.
|
38
|
+
|
39
|
+
[Unreleased]: https://github.com/kbrock/dothtml/compare/v0.1.0...HEAD
|
40
|
+
[0.2.0]: https://github.com/kbrock/dothtml/compare/v0.0.3...v0.1.0
|
41
|
+
[0.0.3]: https://github.com/kbrock/dothtml/compare/v0.0.2...v0.0.3
|
42
|
+
[0.0.2]: https://github.com/kbrock/dothtml/compare/v0.0.1...v0.0.2
|
data/README.md
CHANGED
@@ -4,38 +4,34 @@ Graphviz is a great visualization tool for coding digraphs.
|
|
4
4
|
|
5
5
|
d3 is a great tool for dynamic html presentations.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- provides sample guard file
|
11
|
-
- Rake tasks
|
12
|
-
- hacks class attributes to embed into html file
|
13
|
-
- embeds style into html file
|
14
|
-
|
15
|
-
TODO:
|
16
|
-
- add radio button for class association
|
17
|
-
- embed external svg images into html file
|
18
|
-
|
7
|
+
Dothtml will convert your Graphviz dot files to nicely formatted html files.
|
8
|
+
It can convert them on-demand, or it can constantly convert them as you develop,
|
9
|
+
using a simple [Guard](http://guardgem.org/) process.
|
19
10
|
|
20
11
|
## Installation
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
gem 'dothtml'
|
13
|
+
```
|
14
|
+
gem install dothtml
|
26
15
|
```
|
27
16
|
|
28
|
-
|
17
|
+
## Usage
|
29
18
|
|
30
|
-
|
19
|
+
When starting a project for the first time, just call `dothtml create` with
|
20
|
+
a new directory name. Dothtml will create the directory with a sample.dot file,
|
21
|
+
and then `git init` the directory.
|
31
22
|
|
32
|
-
|
23
|
+
Edit the sample.dot file, or just copy it with a new name, and then call
|
24
|
+
`dothtml build`. That's it! Dothtml has created the .html files.
|
33
25
|
|
34
|
-
|
26
|
+
You can then monitor your live changes to the dot files with `dothtml watch`,
|
27
|
+
which will start a Guard process to monitor them. Change your dot files, and
|
28
|
+
they will be built into .html files upon saving.
|
35
29
|
|
36
|
-
|
30
|
+
Once the Guard process has started, you can also open the .html files in your
|
31
|
+
browser and automatically have then reload with the
|
32
|
+
[LiveReload browser extension](http://livereload.com/extensions/).
|
37
33
|
|
38
|
-
|
34
|
+
You can get more information on the command line with `dothtml --help`
|
39
35
|
|
40
36
|
## Similar Projects
|
41
37
|
|
@@ -43,9 +39,14 @@ TODO: Write usage instructions here
|
|
43
39
|
- https://github.com/kui/octopress-graphviz
|
44
40
|
- https://github.com/glejeune/Ruby-Graphviz
|
45
41
|
|
42
|
+
## TODO
|
43
|
+
|
44
|
+
- Add radio button for class association
|
45
|
+
- Embed external svg images into html file
|
46
|
+
|
46
47
|
## Contributing
|
47
48
|
|
48
|
-
1. Fork it ( https://github.com/
|
49
|
+
1. Fork it ( https://github.com/kbrock/dothtml/fork )
|
49
50
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
51
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
52
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/dothtml.gemspec
CHANGED
@@ -9,18 +9,29 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Keenan Brock"]
|
10
10
|
spec.email = ["keenan@thebrocks.net"]
|
11
11
|
spec.summary = %q{Make conversion of dot to html easier}
|
12
|
-
spec.description =
|
12
|
+
spec.description = <<-DESCRIPTION
|
13
|
+
In a world, full of html, and javascript,
|
14
|
+
there can exist only one graphing library.
|
15
|
+
But there still is hope in trusty graphviz.
|
16
|
+
|
17
|
+
This makes the conversion of dot to html
|
18
|
+
and d3js easier.
|
19
|
+
DESCRIPTION
|
13
20
|
spec.homepage = "http://github.com/kbrock/dothtml"
|
14
21
|
spec.license = "MIT"
|
15
22
|
|
16
23
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
26
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
27
|
spec.require_paths = ["lib"]
|
20
28
|
|
21
|
-
spec.add_dependency 'guard'
|
22
|
-
spec.add_dependency 'guard-rake'
|
23
29
|
spec.add_dependency 'nokogiri'
|
30
|
+
spec.add_dependency 'trollop'
|
31
|
+
spec.add_dependency 'colorize'
|
32
|
+
spec.add_dependency 'guard'
|
33
|
+
spec.add_dependency 'guard-shell'
|
34
|
+
spec.add_dependency 'guard-livereload'
|
24
35
|
# possibly remove this
|
25
36
|
spec.add_dependency 'tilt'
|
26
37
|
|
data/exe/dothtml
ADDED
data/lib/dothtml.rb
CHANGED
data/lib/dothtml/cli.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'dothtml/dot_task'
|
3
|
+
|
4
|
+
module Dothtml
|
5
|
+
class CLI
|
6
|
+
VERSION_STRING = "dothtml #{Dothtml::VERSION}"
|
7
|
+
|
8
|
+
COMMANDS = {
|
9
|
+
"build" => {
|
10
|
+
"usage" => "build [dotfile]",
|
11
|
+
"synopsis" => <<-EOS
|
12
|
+
Builds the specified dotfile (or all .dot files, if not specified)
|
13
|
+
into .svg and .html files. This is the default command if nothing
|
14
|
+
is specified on the command line.
|
15
|
+
EOS
|
16
|
+
},
|
17
|
+
"create" => {
|
18
|
+
"usage" => "create <dir>",
|
19
|
+
"synopsis" => <<-EOS
|
20
|
+
Generates a new Dothtml repo at the indicated dir.
|
21
|
+
EOS
|
22
|
+
},
|
23
|
+
"watch" => {
|
24
|
+
"usage" => "watch",
|
25
|
+
"synopsis" => <<-EOS
|
26
|
+
Starts a guard process, which automatically does a build as .dot
|
27
|
+
files are changed.
|
28
|
+
EOS
|
29
|
+
},
|
30
|
+
}
|
31
|
+
|
32
|
+
COMMAND_NAMES = COMMANDS.keys + %w(version help)
|
33
|
+
DEFAULT_COMMAND = "build"
|
34
|
+
|
35
|
+
attr_reader :args
|
36
|
+
|
37
|
+
def initialize(args)
|
38
|
+
@args = args
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute
|
42
|
+
parse_global_options
|
43
|
+
parse_command_options
|
44
|
+
execute_command
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_accessor :command
|
50
|
+
|
51
|
+
def parse_global_options
|
52
|
+
global_synopsis_parts = COMMANDS.each_value.flat_map do |v|
|
53
|
+
[indent(v["usage"], 1), indent(v["synopsis"], 2)]
|
54
|
+
end
|
55
|
+
global_synopsis = "\nCommands:\n#{global_synopsis_parts.join("\n")}".chomp
|
56
|
+
|
57
|
+
Trollop.options(args) do
|
58
|
+
version VERSION_STRING
|
59
|
+
usage "<command> [command_options]"
|
60
|
+
synopsis global_synopsis
|
61
|
+
stop_on COMMAND_NAMES
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_command_options
|
66
|
+
self.command = (args.shift || DEFAULT_COMMAND).downcase
|
67
|
+
Trollop.die "invalid command, '#{command}'" unless COMMAND_NAMES.include?(command)
|
68
|
+
return unless COMMANDS.key?(command)
|
69
|
+
|
70
|
+
command_options = COMMANDS[command]
|
71
|
+
command_synopsis = "\n#{indent(command_options["synopsis"], 1)}".chomp
|
72
|
+
|
73
|
+
Trollop.options(args) do
|
74
|
+
version VERSION_STRING
|
75
|
+
usage command_options["usage"]
|
76
|
+
synopsis command_synopsis
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def indent(string, amount)
|
81
|
+
prefix = " " * amount
|
82
|
+
string.lines.map { |l| "#{prefix}#{l}" }.join
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Command handlers
|
87
|
+
#
|
88
|
+
|
89
|
+
def execute_command
|
90
|
+
send("#{command}_command")
|
91
|
+
end
|
92
|
+
|
93
|
+
def build_command
|
94
|
+
files =
|
95
|
+
if args.empty?
|
96
|
+
Dir.glob("*.dot").sort
|
97
|
+
else
|
98
|
+
args.select { |a| a.end_with?(".dot") }
|
99
|
+
end
|
100
|
+
|
101
|
+
DotTask.new.build(files)
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_command
|
105
|
+
dir = args.shift
|
106
|
+
Trollop.die "dir not specified" if dir.nil?
|
107
|
+
|
108
|
+
DotTask.new.create(dir)
|
109
|
+
end
|
110
|
+
|
111
|
+
def watch_command
|
112
|
+
guardfile = File.join(TEMPLATES_DIR, "Guardfile")
|
113
|
+
env = {
|
114
|
+
"DOTHTML_PATH" => File.expand_path($0),
|
115
|
+
"BUNDLE_GEMFILE" => File.expand_path("../../Gemfile", __dir__)
|
116
|
+
}
|
117
|
+
exec(env, "bundle exec guard -G #{guardfile}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def version_command
|
121
|
+
puts VERSION_STRING
|
122
|
+
exit 0
|
123
|
+
end
|
124
|
+
|
125
|
+
def help_command
|
126
|
+
Trollop.educate
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/dothtml/dot_helper.rb
CHANGED
@@ -4,6 +4,9 @@ require 'set'
|
|
4
4
|
require 'open3'
|
5
5
|
|
6
6
|
class DotHelper
|
7
|
+
GRAPH_REGEX = /\b(?:di)?graph\b[^\[]*\{/mi
|
8
|
+
DOT_REGEX = /->/
|
9
|
+
|
7
10
|
def initialize(svg_contents)
|
8
11
|
@svg_contents = svg_contents
|
9
12
|
end
|
@@ -16,9 +19,21 @@ class DotHelper
|
|
16
19
|
@dom ||= parse_dom(@svg_contents)
|
17
20
|
end
|
18
21
|
|
22
|
+
# return the list of choices provided for a user
|
23
|
+
#
|
24
|
+
# these choices are displayed to modify the data
|
25
|
+
# on the page
|
26
|
+
#
|
27
|
+
# this will add a body css class and trigger a data
|
28
|
+
# event for d3js
|
19
29
|
def extractChoices
|
20
30
|
end
|
21
31
|
|
32
|
+
# return true if the nodes have descripions?
|
33
|
+
#
|
34
|
+
# This will create a div box where descriptions
|
35
|
+
# can be displayed
|
36
|
+
#
|
22
37
|
def descriptions?
|
23
38
|
#dom.css("")
|
24
39
|
end
|
@@ -27,7 +42,9 @@ class DotHelper
|
|
27
42
|
dom.css("title").first.content()
|
28
43
|
end
|
29
44
|
|
30
|
-
#
|
45
|
+
# Embed svg image links directly into the document
|
46
|
+
#
|
47
|
+
# this currently has too many issues
|
31
48
|
# working on making this more friendly
|
32
49
|
# assume unique list of filenames
|
33
50
|
def images
|
@@ -67,34 +84,23 @@ class DotHelper
|
|
67
84
|
end
|
68
85
|
end
|
69
86
|
|
70
|
-
def merge_id_class(old_id, old_class)
|
71
|
-
new_id, new_class = extract_id_class(old_id)
|
72
|
-
[new_id, [old_class, new_class].compact.join(" ")]
|
73
|
-
end
|
74
|
-
|
75
|
-
# some nodes are of the form <div id="x1 class='other'" class="c1">
|
76
|
-
# assume (class= is present)
|
77
|
-
def fix_node_id(node)
|
78
|
-
new_id, new_class = merge_id_class(node["id"], node["class"])
|
79
|
-
node["id"] = new_id
|
80
|
-
node["class"] = new_class
|
81
|
-
node
|
82
|
-
end
|
83
|
-
|
84
87
|
def embed_images
|
85
|
-
|
88
|
+
node.children.before(images)
|
86
89
|
self
|
87
90
|
end
|
88
91
|
|
89
|
-
def
|
90
|
-
dom.xpath(
|
92
|
+
def remove_comments
|
93
|
+
dom.xpath('//comment()').each { |comment| comment.remove }
|
91
94
|
self
|
92
95
|
end
|
93
96
|
|
97
|
+
def node
|
98
|
+
dom.at("svg")
|
99
|
+
end
|
94
100
|
|
95
101
|
# uses a fragment to remove extra xml declarations
|
96
102
|
def to_xml
|
97
|
-
|
103
|
+
node.to_xml
|
98
104
|
end
|
99
105
|
|
100
106
|
def write(file_name, template_name, locals)
|
@@ -105,12 +111,36 @@ class DotHelper
|
|
105
111
|
new(svg_from_dot(File.read(filename)))
|
106
112
|
end
|
107
113
|
|
108
|
-
def self.
|
109
|
-
|
114
|
+
def self.detect_language(contents, language = nil)
|
115
|
+
language || ((contents =~ DOT_REGEX) ? 'dot' : 'neato')
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.enhance(contents, language)
|
119
|
+
if contents =~ GRAPH_REGEX
|
120
|
+
contents
|
121
|
+
elsif language == 'dot'
|
122
|
+
<<-GRAPH
|
123
|
+
digraph {
|
124
|
+
#{contents}
|
125
|
+
}
|
126
|
+
GRAPH
|
127
|
+
else
|
128
|
+
<<-GRAPH
|
129
|
+
graph {
|
130
|
+
#{contents}
|
131
|
+
}
|
132
|
+
GRAPH
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.from_dot(contents, language = 'dot')
|
137
|
+
language = detect_language(contents, language)
|
138
|
+
contents = enhance(contents, language)
|
139
|
+
new(svg_from_dot(contents, language))
|
110
140
|
end
|
111
141
|
|
112
|
-
def self.svg_from_dot(contents)
|
113
|
-
Open3.popen3(
|
142
|
+
def self.svg_from_dot(contents, language = 'dot')
|
143
|
+
Open3.popen3("#{language} -Tsvg") do |stdin, stdout, stderr|
|
114
144
|
stdout.binmode
|
115
145
|
stdin.print contents
|
116
146
|
stdin.close
|
data/lib/dothtml/dot_task.rb
CHANGED
@@ -1,78 +1,106 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake/tasklib'
|
3
|
-
require_relative 'dot_helper'
|
1
|
+
require 'dothtml/dot_helper'
|
4
2
|
|
5
3
|
module Dothtml
|
6
|
-
class DotTask
|
4
|
+
class DotTask
|
7
5
|
attr_accessor :template
|
8
6
|
attr_accessor :style
|
9
7
|
attr_accessor :behavior
|
10
8
|
attr_accessor :cdn
|
11
9
|
attr_accessor :d3js
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
templates = File.expand_path(File.join(File.dirname(__FILE__), "..", "..","templates"))
|
18
|
-
@name = name
|
19
|
-
@style = File.join(templates, 'style.css')
|
20
|
-
@behavior = File.join(templates, 'behavior.js')
|
21
|
-
@template = File.join(templates, 'index.html.erb')
|
11
|
+
def initialize
|
12
|
+
@style = File.join(TEMPLATES_DIR, 'style.css')
|
13
|
+
@behavior = File.join(TEMPLATES_DIR, 'behavior.js')
|
14
|
+
@template = File.join(TEMPLATES_DIR, 'index.html.erb')
|
22
15
|
self.cdn = true
|
23
16
|
yield self if block_given?
|
24
|
-
define
|
25
17
|
end
|
26
18
|
|
27
19
|
def cdn=(val)
|
28
|
-
@
|
20
|
+
@cdn = val
|
21
|
+
@d3js = case val
|
22
|
+
when true then "//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"
|
23
|
+
when false then "d3.v3.js"
|
24
|
+
else val
|
25
|
+
end
|
29
26
|
end
|
30
27
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
target = params[:target]
|
36
|
-
|
37
|
-
puts "#{source} -> #{target}"
|
38
|
-
|
39
|
-
doc = DotHelper.from_dotfile(source).fix_ids#.embed_images
|
40
|
-
doc.write target, @template,
|
41
|
-
title: doc.extractTitle,
|
42
|
-
body: doc.to_xml,
|
43
|
-
choices: doc.extractChoices,
|
44
|
-
descriptions: doc.descriptions?,
|
45
|
-
style: File.read(style),
|
46
|
-
behavior: File.read(behavior),
|
47
|
-
d3js: d3js
|
28
|
+
def build(*files)
|
29
|
+
files.flatten.each do |f|
|
30
|
+
dot_to_svg(f)
|
31
|
+
dot_to_html(f)
|
48
32
|
end
|
33
|
+
end
|
49
34
|
|
50
|
-
|
51
|
-
|
52
|
-
source = params[:src]
|
53
|
-
target = params[:target]
|
54
|
-
|
55
|
-
puts "#{source} -> #{target}"
|
35
|
+
def create(dir)
|
36
|
+
require 'colorize'
|
56
37
|
|
57
|
-
|
58
|
-
|
38
|
+
if Dir.exists?(dir)
|
39
|
+
say_status(:exists, dir)
|
40
|
+
else
|
41
|
+
FileUtils.mkdir_p(dir)
|
42
|
+
say_status(:create, dir)
|
59
43
|
end
|
60
44
|
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
sample = File.join(dir, "sample.dot")
|
46
|
+
if File.exists?(sample)
|
47
|
+
say_status(:exists, sample)
|
48
|
+
else
|
49
|
+
sample_source = File.join(TEMPLATES_DIR, "sample.dot")
|
50
|
+
FileUtils.cp(sample_source, sample)
|
51
|
+
say_status(:create, sample)
|
64
52
|
end
|
65
53
|
|
66
|
-
|
67
|
-
|
54
|
+
gitignore = File.join(dir, ".gitignore")
|
55
|
+
if File.exists?(gitignore)
|
56
|
+
say_status(:exists, gitignore)
|
57
|
+
else
|
58
|
+
File.write(gitignore, "*.html\n*.svg")
|
59
|
+
say_status(:create, gitignore)
|
68
60
|
end
|
69
61
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
62
|
+
git_dir = File.join(dir, ".git")
|
63
|
+
if Dir.exists?(git_dir)
|
64
|
+
say_status(:exists, git_dir)
|
65
|
+
else
|
66
|
+
system("git init", :chdir => dir)
|
75
67
|
end
|
76
68
|
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def dot_to_html(source)
|
73
|
+
target = source.sub(/.dot$/, ".html")
|
74
|
+
puts "#{source} -> #{target}"
|
75
|
+
|
76
|
+
doc = DotHelper.from_dotfile(source)#.embed_images
|
77
|
+
doc.write target, @template,
|
78
|
+
title: doc.extractTitle,
|
79
|
+
body: doc.to_xml,
|
80
|
+
choices: doc.extractChoices,
|
81
|
+
descriptions: doc.descriptions?,
|
82
|
+
style: File.read(style),
|
83
|
+
behavior: File.read(behavior),
|
84
|
+
d3js: d3js
|
85
|
+
end
|
86
|
+
|
87
|
+
def dot_to_svg(source)
|
88
|
+
target = source.sub(/.dot$/, ".svg")
|
89
|
+
puts "#{source} -> #{target}"
|
90
|
+
|
91
|
+
doc = DotHelper.from_dotfile(source)#.embed_images
|
92
|
+
File.write(target, doc.to_xml)
|
93
|
+
end
|
94
|
+
|
95
|
+
def say_status(mode, text)
|
96
|
+
mode_text =
|
97
|
+
case mode
|
98
|
+
when :exists then mode.to_s.yellow.bold
|
99
|
+
when :create then mode.to_s.green.bold
|
100
|
+
else mode.to_s.bold
|
101
|
+
end
|
102
|
+
|
103
|
+
puts "\t#{mode_text}\t#{text}"
|
104
|
+
end
|
77
105
|
end
|
78
106
|
end
|
data/lib/dothtml/version.rb
CHANGED
data/templates/Guardfile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
guard
|
2
|
-
watch(/.dot$/)
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
guard :shell do
|
2
|
+
watch(/.dot$/) do |m|
|
3
|
+
dothtml_path = ENV["DOTHTML_PATH"] || "dothtml"
|
4
|
+
system("#{dothtml_path} build #{m.join(" ")}")
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
guard :livereload do
|
9
|
+
watch(/.html$/)
|
6
10
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
digraph Sample {
|
2
|
+
graph [ fontname="Helvetica-Bold" ]
|
3
|
+
node [ id="\N" shape="Mrecord" style="filled" fontname="Helvetica" fillcolor="#ffffff" penwidth="2" ]
|
4
|
+
edge [ arrowsize="0.5" fontname="Helvetica" ]
|
5
|
+
|
6
|
+
label="Sample"
|
7
|
+
style="rounded"
|
8
|
+
|
9
|
+
object1 -> object2
|
10
|
+
object1 -> object3
|
11
|
+
object2 -> object4 [style="dotted"]
|
12
|
+
object3 -> object4 [style="dashed"]
|
13
|
+
}
|
data/test/test_dot_helper.rb
CHANGED
@@ -5,46 +5,6 @@ class TestDotHelper < Minitest::Test
|
|
5
5
|
DotHelper.new contents
|
6
6
|
end
|
7
7
|
|
8
|
-
def test_extract_id_class_with_id
|
9
|
-
assert_equal ["x1"], dot_helper.extract_id_class("x1")
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_extract_id_class_with_class_eq
|
13
|
-
assert_equal ["", "x1"], dot_helper.extract_id_class("class=x1")
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_extract_id_class_with_id_class_eq
|
17
|
-
assert_equal ["x1", "c1"], dot_helper.extract_id_class("x1 class=c1")
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_extract_id_class_with_id_class_eq_quote
|
21
|
-
assert_equal ["x1", "c1"], dot_helper.extract_id_class("x1 class='c1'")
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_extract_id_class_with_id_class_eq_dbl_quote
|
25
|
-
assert_equal ["x1", "c1"], dot_helper.extract_id_class('x1 class="c1"')
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_merge_id_class_with_id_class_eq_and_class
|
29
|
-
assert_equal ["x1", "c0 c1"], dot_helper.merge_id_class('x1 class="c1"', "c0")
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_merge_id_class_with_id_multi_class_eq_and_class
|
33
|
-
assert_equal ["x1", "c0 c1 c2"], dot_helper.merge_id_class('x1 class="c1 c2"', "c0")
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_fix_node_id_with_id_class_eq_and_class
|
37
|
-
node = dot_helper.fix_node_id(dom(%{<x><div id="x1 class=c1"></div></x>}, "div"))
|
38
|
-
assert_equal "x1", node["id"]
|
39
|
-
assert_equal "c1", node["class"]
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_fix_ids
|
43
|
-
node = dot_helper(%{<x><div id="x1 class=c1" class="c0"></div></x>}).fix_ids.dom
|
44
|
-
assert_equal "x1", node.at("div")["id"]
|
45
|
-
assert_equal "c0 c1", node.at("div")["class"]
|
46
|
-
end
|
47
|
-
|
48
8
|
private
|
49
9
|
|
50
10
|
def dom(contents, at=nil)
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dothtml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keenan Brock
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: trollop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: guard
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +67,7 @@ dependencies:
|
|
25
67
|
- !ruby/object:Gem::Version
|
26
68
|
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: guard-
|
70
|
+
name: guard-shell
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
73
|
- - ">="
|
@@ -39,7 +81,7 @@ dependencies:
|
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
84
|
+
name: guard-livereload
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - ">="
|
@@ -108,7 +150,13 @@ dependencies:
|
|
108
150
|
- - ">="
|
109
151
|
- !ruby/object:Gem::Version
|
110
152
|
version: '0'
|
111
|
-
description:
|
153
|
+
description: |2
|
154
|
+
In a world, full of html, and javascript,
|
155
|
+
there can exist only one graphing library.
|
156
|
+
But there still is hope in trusty graphviz.
|
157
|
+
|
158
|
+
This makes the conversion of dot to html
|
159
|
+
and d3js easier.
|
112
160
|
email:
|
113
161
|
- keenan@thebrocks.net
|
114
162
|
executables:
|
@@ -123,18 +171,18 @@ files:
|
|
123
171
|
- LICENSE.txt
|
124
172
|
- README.md
|
125
173
|
- Rakefile
|
126
|
-
- bin/dothtml
|
127
174
|
- dothtml.gemspec
|
175
|
+
- exe/dothtml
|
128
176
|
- lib/dothtml.rb
|
177
|
+
- lib/dothtml/cli.rb
|
129
178
|
- lib/dothtml/dot_helper.rb
|
130
179
|
- lib/dothtml/dot_task.rb
|
131
180
|
- lib/dothtml/version.rb
|
132
|
-
- templates/Gemfile
|
133
181
|
- templates/Guardfile
|
134
|
-
- templates/Rakefile
|
135
182
|
- templates/behavior.js
|
136
183
|
- templates/d3.v3.js
|
137
184
|
- templates/index.html.erb
|
185
|
+
- templates/sample.dot
|
138
186
|
- templates/style.css
|
139
187
|
- test/minitest_helper.rb
|
140
188
|
- test/test_dot_helper.rb
|
@@ -160,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
208
|
version: '0'
|
161
209
|
requirements: []
|
162
210
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
211
|
+
rubygems_version: 2.4.5
|
164
212
|
signing_key:
|
165
213
|
specification_version: 4
|
166
214
|
summary: Make conversion of dot to html easier
|
data/bin/dothtml
DELETED
data/templates/Gemfile
DELETED
data/templates/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
|
2
|
-
# Rakefile to build dot files
|
3
|
-
# dependencies:
|
4
|
-
# mac
|
5
|
-
# graphviz to convert dot files to svg
|
6
|
-
|
7
|
-
require "dothtml/dot_task"
|
8
|
-
|
9
|
-
Dothtml::DotTask.new do |t|
|
10
|
-
#t.cdn = true
|
11
|
-
#t.template = 'index.html.liquid'
|
12
|
-
#t.style = 'style.css'
|
13
|
-
#t.behavior = 'behavior.js'
|
14
|
-
end
|
15
|
-
|
16
|
-
task :default => :html
|
17
|
-
|
18
|
-
#task :html => %w(file1.html file2.html)
|
19
|
-
task :html do
|
20
|
-
Dir.glob("*.dot").each do |f|
|
21
|
-
Rake::Task[f.sub(/\.dot$/, '.html')].invoke
|
22
|
-
end
|
23
|
-
end
|