asciidoctor-diagram 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +15 -0
- data/README.adoc +5 -1
- data/lib/asciidoctor-diagram-java-1.3.7.jar +0 -0
- data/lib/asciidoctor-diagram.rb +2 -1
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +21 -17
- data/lib/asciidoctor-diagram/ditaa/extension.rb +1 -1
- data/lib/asciidoctor-diagram/extensions.rb +12 -6
- data/lib/asciidoctor-diagram/graphviz/extension.rb +4 -1
- data/lib/asciidoctor-diagram/plantuml/extension.rb +22 -2
- data/lib/asciidoctor-diagram/shaape/extension.rb +4 -1
- data/lib/asciidoctor-diagram/util/cli_generator.rb +32 -16
- data/lib/asciidoctor-diagram/util/java.rb +19 -1
- data/lib/asciidoctor-diagram/util/java_socket.rb +4 -4
- data/lib/asciidoctor-diagram/util/which.rb +28 -9
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/asciidoctor-diagram/wavedrom.rb +9 -0
- data/lib/asciidoctor-diagram/wavedrom/extension.rb +39 -0
- data/spec/blockdiag_spec.rb +1 -0
- data/spec/plantuml_spec.rb +27 -0
- data/spec/shaape_spec.rb +3 -2
- data/spec/test_helper.rb +3 -0
- data/spec/wavedrom_spec.rb +214 -0
- metadata +7 -3
- data/lib/asciidoctor-diagram-java-1.3.4.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13041fe1a06833bb670496dbe28c3fb3adf23ae2
|
4
|
+
data.tar.gz: 858a4b0482f58e3e4593a04dfd3e3fa3103632cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001e2013fe9d1b9263f2b015dd0cb62f1471b097204def7f216892643bff0b2324936690889234b5838c29ba5221cbdb16bec800119425ce8cbafa0dd22ee89a
|
7
|
+
data.tar.gz: ceeafbd38f5648f651aee4ee0d691f561392406c8222949058b8a377d34e38e78e3ace0b6cfc3a4769f8e1760d4a696bf39b06c0666ba9028f80ff5ced9b5243
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
= Asciidoctor-diagram Changelog
|
2
2
|
|
3
|
+
== 1.3.2
|
4
|
+
|
5
|
+
Enhancements::
|
6
|
+
|
7
|
+
* Add support for WaveDrom diagrams (requires WaveDrom Editor to be installed separately)
|
8
|
+
* Allow error handling to be controlled using the `diagram-on-error` attribute.
|
9
|
+
Setting this attribute to `log` (default) logs an error message and continues processing of the document.
|
10
|
+
Setting it to `abort` triggers an exception and aborts document processing.
|
11
|
+
* Resolve relative image references in PlantUML diagrams to absolute ones up front to ensure PlantUML can locate the images
|
12
|
+
|
13
|
+
Bug Fixes::
|
14
|
+
|
15
|
+
* Issue #83: Omit stack trace information from error message that gets embedded in the output document
|
16
|
+
* Issue #84: Restore support for specifying the location of the `dot` executable using the `graphvizdot` attribute
|
17
|
+
|
3
18
|
== 1.3.1
|
4
19
|
|
5
20
|
Bug Fixes::
|
data/README.adoc
CHANGED
@@ -9,6 +9,7 @@ These extensions allow you to embed plain text diagrams inside your AsciiDoc doc
|
|
9
9
|
- https://github.com/christiangoltz/shaape[Shaape]
|
10
10
|
- http://blockdiag.com[BlockDiag, SeqDiag, ActDiag, NwDiag]
|
11
11
|
- http://www.graphviz.org/content/dot-language[GraphViz DOT]
|
12
|
+
- http://wavedrom.com[WaveDrom]
|
12
13
|
|
13
14
|
The extension takes care of running the diagram processor to generate the images from the input text and insert them into the rendered document.
|
14
15
|
|
@@ -43,6 +44,7 @@ Certain diagram types require other tools to be installed seperately.
|
|
43
44
|
- PlantUML and Graphviz: the Graphviz `dot` tool.
|
44
45
|
- Shaape: the Shaape Python package
|
45
46
|
- Block/Seq/Act/Nw diag: the block/seq/act/nw diag Python packages
|
47
|
+
- WaveDrom: the https://github.com/wavedrom/wavedrom.github.io/releases[WaveDrom editor] application
|
46
48
|
|
47
49
|
== Usage
|
48
50
|
|
@@ -58,6 +60,7 @@ In your script you can then either require one or more of the following files:
|
|
58
60
|
. `asciidoctor-diagram/graphviz`: to enable the graphviz extension
|
59
61
|
. `asciidoctor-diagram/plantuml`: to enable the plantuml extension
|
60
62
|
. `asciidoctor-diagram/shaape`: to enable the shaape extension
|
63
|
+
. `asciidoctor-diagram/wavedrom`: to enable the wavedrom extension
|
61
64
|
|
62
65
|
Requiring one or more of these files will automatically register the extensions for all processed documents.
|
63
66
|
If you need more fine grained control over when the extensions are enabled or not, `asciidoctor-diagram/ditaa/extension`, `asciidoctor-diagram/graphviz/extension` and `asciidoctor-diagram/plantuml/extension` can be used instead.
|
@@ -73,6 +76,7 @@ Once the extensions are enabled the following block types becomes available for
|
|
73
76
|
- `graphviz`
|
74
77
|
- `plantuml`
|
75
78
|
- `shaape`
|
79
|
+
- `wavedrom`
|
76
80
|
|
77
81
|
Detailed descriptions of the supported syntax inside these blocks is available on the http://plantuml.sourceforge.net/[PlantUML], http://www.graphviz.org/content/dot-language[Graphviz] and http://ditaa.sourceforge.net/[ditaa] websites.
|
78
82
|
|
@@ -98,7 +102,7 @@ The diagram blocks support the following attributes:
|
|
98
102
|
. `format` (or 3rd position): the output format. PlantUML blocks support `png`, `svg` and `txt`. Graphviz, Shaape and BlockDiag support `png` and `svg`. Ditaa only supports `png`.
|
99
103
|
|
100
104
|
Once you have all of this in place and your original AsciiDoc file contains a diagram block, it's time to build it into an HTML file with Asciidoctor Diagram magic!
|
101
|
-
When executing Asciidoctor, you must reference the Adciidoctor Diagram library, otherwise your
|
105
|
+
When executing Asciidoctor, you must reference the Adciidoctor Diagram library, otherwise your diagram blocks won't be recognized as such. When executing Asciidoctor from the command line, do it using the -r parameter to reference this external library:
|
102
106
|
|
103
107
|
$ asciidoctor -r asciidoctor-diagram doc.adoc
|
104
108
|
|
Binary file
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -3,4 +3,5 @@ require 'asciidoctor-diagram/ditaa'
|
|
3
3
|
require 'asciidoctor-diagram/graphviz'
|
4
4
|
require 'asciidoctor-diagram/plantuml'
|
5
5
|
require 'asciidoctor-diagram/salt'
|
6
|
-
require 'asciidoctor-diagram/shaape'
|
6
|
+
require 'asciidoctor-diagram/shaape'
|
7
|
+
require 'asciidoctor-diagram/wavedrom'
|
@@ -1,24 +1,9 @@
|
|
1
1
|
require_relative '../extensions'
|
2
2
|
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/which'
|
3
4
|
|
4
5
|
module Asciidoctor
|
5
6
|
module Diagram
|
6
|
-
# @private
|
7
|
-
module BlockDiag
|
8
|
-
def self.define_processors(name, &init)
|
9
|
-
block = Class.new(Extensions::DiagramBlockProcessor) do
|
10
|
-
self.instance_eval &init
|
11
|
-
end
|
12
|
-
::Asciidoctor::Diagram.const_set("#{name}BlockProcessor", block)
|
13
|
-
|
14
|
-
block_macro = Class.new(Extensions::DiagramBlockMacroProcessor) do
|
15
|
-
self.instance_eval &init
|
16
|
-
end
|
17
|
-
|
18
|
-
::Asciidoctor::Diagram.const_set("#{name}BlockMacroProcessor", block_macro)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
7
|
# @!parse
|
23
8
|
# # Block processor converts blockdiag code into images.
|
24
9
|
# #
|
@@ -84,11 +69,30 @@ module Asciidoctor
|
|
84
69
|
# #
|
85
70
|
# # Supports PNG and SVG output.
|
86
71
|
# class PacketDiagBlockMacroProcessor < API::DiagramBlockMacroProcessor; end
|
72
|
+
|
73
|
+
# @private
|
74
|
+
module BlockDiag
|
75
|
+
def self.define_processors(name, &init)
|
76
|
+
block = Class.new(Extensions::DiagramBlockProcessor) do
|
77
|
+
self.instance_eval &init
|
78
|
+
end
|
79
|
+
::Asciidoctor::Diagram.const_set("#{name}BlockProcessor", block)
|
80
|
+
|
81
|
+
block_macro = Class.new(Extensions::DiagramBlockMacroProcessor) do
|
82
|
+
self.instance_eval &init
|
83
|
+
end
|
84
|
+
|
85
|
+
::Asciidoctor::Diagram.const_set("#{name}BlockMacroProcessor", block_macro)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
87
89
|
['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
|
88
90
|
BlockDiag.define_processors(tool) do
|
91
|
+
include Which
|
92
|
+
|
89
93
|
[:png, :svg].each do |f|
|
90
94
|
register_format(f, :image) do |c, p|
|
91
|
-
CliGenerator.
|
95
|
+
CliGenerator.generate_stdin(which(p, tool.downcase), c.to_s) do |tool_path, output_path|
|
92
96
|
[tool_path, '-o', output_path, "-T#{f.to_s}", '-']
|
93
97
|
end
|
94
98
|
end
|
@@ -103,11 +103,17 @@ module Asciidoctor
|
|
103
103
|
create_image_block(parent, source, format, generator_info)
|
104
104
|
end
|
105
105
|
rescue => e
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
case parent.attr('diagram-on-error') || 'log'
|
107
|
+
when 'abort'
|
108
|
+
raise e
|
109
|
+
else
|
110
|
+
text = "Failed to generate image: #{e.message}"
|
111
|
+
warn %(asciidoctor-diagram: ERROR: #{text})
|
112
|
+
text << "\n"
|
113
|
+
text << source.code
|
114
|
+
Asciidoctor::Block.new parent, :listing, :source => text, :attributes => attributes
|
115
|
+
end
|
116
|
+
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
@@ -153,7 +159,7 @@ module Asciidoctor
|
|
153
159
|
metadata = source.create_image_metadata
|
154
160
|
metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
|
155
161
|
|
156
|
-
FileUtils.mkdir_p(image_dir) unless Dir.
|
162
|
+
FileUtils.mkdir_p(image_dir) unless Dir.exist?(image_dir)
|
157
163
|
File.open(image_file, 'wb') { |f| f.write result }
|
158
164
|
File.open(metadata_file, 'w') { |f| JSON.dump(metadata, f) }
|
159
165
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require_relative '../extensions'
|
2
2
|
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/which'
|
3
4
|
|
4
5
|
module Asciidoctor
|
5
6
|
module Diagram
|
6
7
|
# @private
|
7
8
|
module Graphviz
|
9
|
+
include Which
|
10
|
+
|
8
11
|
def self.included(mod)
|
9
12
|
[:png, :svg].each do |f|
|
10
13
|
mod.register_format(f, :image) do |c, p|
|
11
|
-
CliGenerator.
|
14
|
+
CliGenerator.generate_stdin(which(p, 'dot', :attr_names => ['dot', 'graphvizdot']), c.to_s) do |tool_path, output_path|
|
12
15
|
[tool_path, "-o#{output_path}", "-T#{f.to_s}"]
|
13
16
|
end
|
14
17
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../extensions'
|
2
|
+
require_relative '../util/which'
|
2
3
|
|
3
4
|
module Asciidoctor
|
4
5
|
module Diagram
|
@@ -14,7 +15,7 @@ module Asciidoctor
|
|
14
15
|
def plantuml(parent, code, tag, mime_type)
|
15
16
|
Java.load
|
16
17
|
|
17
|
-
code =
|
18
|
+
code = preprocess_code(parent, code, tag)
|
18
19
|
|
19
20
|
headers = {
|
20
21
|
'Accept' => mime_type
|
@@ -32,12 +33,31 @@ module Asciidoctor
|
|
32
33
|
)
|
33
34
|
|
34
35
|
unless response[:code] == 200
|
35
|
-
raise "PlantUML image generation failed
|
36
|
+
raise Java.create_error("PlantUML image generation failed", response)
|
36
37
|
end
|
37
38
|
|
38
39
|
response[:body]
|
39
40
|
end
|
40
41
|
|
42
|
+
def preprocess_code(parent, code, tag)
|
43
|
+
code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index "@start#{tag}"
|
44
|
+
|
45
|
+
code.gsub!(/(?<=<img:)[^>]+(?=>)/) do |match|
|
46
|
+
if match =~ URI.regexp
|
47
|
+
uri = URI.parse(match)
|
48
|
+
if uri.scheme == 'file'
|
49
|
+
parent.normalize_system_path(uri.path, parent.attr('imagesdir'))
|
50
|
+
else
|
51
|
+
parent.normalize_web_path(match)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
parent.normalize_system_path(match, parent.attr('imagesdir'))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
code
|
59
|
+
end
|
60
|
+
|
41
61
|
def self.included(mod)
|
42
62
|
mod.register_format(:png, :image) do |c, p|
|
43
63
|
plantuml(p, c.to_s, mod.tag, 'image/png')
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require_relative '../extensions'
|
2
2
|
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/which'
|
3
4
|
|
4
5
|
module Asciidoctor
|
5
6
|
module Diagram
|
6
7
|
# @private
|
7
8
|
module Shaape
|
9
|
+
include Which
|
10
|
+
|
8
11
|
def self.included(mod)
|
9
12
|
[:png, :svg].each do |f|
|
10
13
|
mod.register_format(f, :image) do |c, p|
|
11
|
-
CliGenerator.
|
14
|
+
CliGenerator.generate_stdin(which(p, 'shaape'), c.to_s) do |tool_path, output_path|
|
12
15
|
[tool_path, '-o', output_path, '-t', f.to_s, '-']
|
13
16
|
end
|
14
17
|
end
|
@@ -1,41 +1,57 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
|
3
|
-
require_relative '../util/java'
|
4
|
-
require_relative '../util/which'
|
5
|
-
|
6
3
|
module Asciidoctor
|
7
4
|
module Diagram
|
8
5
|
# @private
|
9
6
|
module CliGenerator
|
10
|
-
def self.
|
11
|
-
|
12
|
-
|
13
|
-
tool_path = instance_variable_get(tool_var)
|
14
|
-
unless tool_path
|
15
|
-
tool_path = parent.document.attributes[tool]
|
16
|
-
tool_path = ::Asciidoctor::Diagram.which(tool) unless tool_path && File.executable?(tool_path)
|
17
|
-
raise "Could not find the '#{tool}' executable in PATH; add it to the PATH or specify its location using the '#{tool}' document attribute" unless tool_path
|
18
|
-
instance_variable_set(tool_var, tool_path)
|
19
|
-
end
|
7
|
+
def self.generate_stdin(tool, code)
|
8
|
+
tool_name = File.basename(tool)
|
20
9
|
|
21
|
-
target_file = Tempfile.new(
|
10
|
+
target_file = Tempfile.new(tool_name)
|
22
11
|
begin
|
23
12
|
target_file.close
|
24
13
|
|
25
|
-
args = yield
|
14
|
+
args = yield tool, target_file.path
|
26
15
|
|
27
16
|
IO.popen(args, "w") do |io|
|
28
17
|
io.write code
|
29
18
|
end
|
30
19
|
result_code = $?
|
31
20
|
|
32
|
-
raise "#{
|
21
|
+
raise "#{tool_name} image generation failed" unless result_code == 0
|
33
22
|
|
34
23
|
File.binread(target_file.path)
|
35
24
|
ensure
|
36
25
|
target_file.unlink
|
37
26
|
end
|
38
27
|
end
|
28
|
+
|
29
|
+
def self.generate_file(tool, code)
|
30
|
+
tool_name = File.basename(tool)
|
31
|
+
|
32
|
+
source_file = Tempfile.new(tool_name)
|
33
|
+
begin
|
34
|
+
File.write(source_file.path, code)
|
35
|
+
|
36
|
+
target_file = Tempfile.new(tool_name)
|
37
|
+
begin
|
38
|
+
target_file.close
|
39
|
+
|
40
|
+
args = yield tool, source_file.path, target_file.path
|
41
|
+
|
42
|
+
system(*args)
|
43
|
+
result_code = $?
|
44
|
+
|
45
|
+
raise "#{tool_name} image generation failed" unless result_code == 0
|
46
|
+
|
47
|
+
File.binread(target_file.path)
|
48
|
+
ensure
|
49
|
+
target_file.unlink
|
50
|
+
end
|
51
|
+
ensure
|
52
|
+
source_file.unlink
|
53
|
+
end
|
54
|
+
end
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Asciidoctor
|
2
4
|
module Diagram
|
3
5
|
# @private
|
4
6
|
module Java
|
5
7
|
def self.classpath
|
6
8
|
@classpath ||= [
|
7
|
-
File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.
|
9
|
+
File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.7.jar'), File.dirname(__FILE__))
|
8
10
|
]
|
9
11
|
end
|
10
12
|
|
@@ -70,6 +72,22 @@ module Asciidoctor
|
|
70
72
|
|
71
73
|
resp
|
72
74
|
end
|
75
|
+
|
76
|
+
def self.create_error(prefix_msg, response)
|
77
|
+
content_type = response[:headers]['Content-Type'] || 'text/plain'
|
78
|
+
if content_type.start_with? 'application/json'
|
79
|
+
json = JSON.parse(response[:body].force_encoding(Encoding::UTF_8))
|
80
|
+
ruby_bt = Kernel.caller(2)
|
81
|
+
java_bt = json['stk'].map { |java_line| "#{java_line[0]}:#{java_line[3]}: in `#{java_line[2]}'" }
|
82
|
+
error = RuntimeError.new("#{prefix_msg}: #{json['msg']}")
|
83
|
+
error.set_backtrace java_bt + ruby_bt
|
84
|
+
raise error
|
85
|
+
elsif content_type.start_with? 'text/plain'
|
86
|
+
raise "#{prefix_msg}: #{response[:reason]} #{response[:body].force_encoding(Encoding::UTF_8)}"
|
87
|
+
else
|
88
|
+
raise "#{prefix_msg}: #{response[:reason]}"
|
89
|
+
end
|
90
|
+
end
|
73
91
|
end
|
74
92
|
end
|
75
93
|
end
|
@@ -16,7 +16,7 @@ module Asciidoctor
|
|
16
16
|
args << '-cp'
|
17
17
|
# special case for cygwin, it requires path translation for java to work
|
18
18
|
if RbConfig::CONFIG['host_os'] =~ /cygwin/i
|
19
|
-
cygpath = ::Asciidoctor::Diagram.which('cygpath')
|
19
|
+
cygpath = ::Asciidoctor::Diagram::Which.which('cygpath')
|
20
20
|
if(cygpath != nil)
|
21
21
|
args << classpath.flatten.map { |jar| `cygpath -w "#{jar}"`.strip }.join(";")
|
22
22
|
else
|
@@ -79,13 +79,13 @@ module Asciidoctor
|
|
79
79
|
def self.find_java
|
80
80
|
if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
81
81
|
# Windows
|
82
|
-
path_to(ENV['JAVA_HOME'], 'bin/java.exe') || registry_lookup || ::Asciidoctor::Diagram.which('java')
|
82
|
+
path_to(ENV['JAVA_HOME'], 'bin/java.exe') || registry_lookup || ::Asciidoctor::Diagram::Which.which('java')
|
83
83
|
elsif /darwin/ =~ RUBY_PLATFORM
|
84
84
|
# Mac
|
85
|
-
path_to(ENV['JAVA_HOME'], 'bin/java') || path_to(`/usr/libexec/java_home`.strip, 'bin/java') || ::Asciidoctor::Diagram.which('java')
|
85
|
+
path_to(ENV['JAVA_HOME'], 'bin/java') || path_to(`/usr/libexec/java_home`.strip, 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
|
86
86
|
else
|
87
87
|
# Other unix-like system
|
88
|
-
path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram.which('java')
|
88
|
+
path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -1,15 +1,34 @@
|
|
1
1
|
module Asciidoctor
|
2
2
|
module Diagram
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Which
|
4
|
+
# @private
|
5
|
+
def self.which(cmd, options = {})
|
6
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
7
|
+
|
8
|
+
paths = (options[:path] || []) + ENV['PATH'].split(File::PATH_SEPARATOR)
|
9
|
+
paths.each do |path|
|
10
|
+
exts.each { |ext|
|
11
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
12
|
+
return exe if File.executable? exe
|
13
|
+
}
|
14
|
+
end
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def which(parent_block, cmd, options = {})
|
19
|
+
attr_names = options[:attr_names] || [cmd]
|
20
|
+
|
21
|
+
cmd_var = '@' + attr_names[0]
|
22
|
+
|
23
|
+
cmd_path = instance_variable_get(cmd_var)
|
24
|
+
unless cmd_path
|
25
|
+
cmd_path = attr_names.map { |attr_name| parent_block.document.attributes[attr_name] }.find { |attr| !attr.nil? }
|
26
|
+
cmd_path = ::Asciidoctor::Diagram::Which.which(cmd, :path => options[:path]) unless cmd_path && File.executable?(cmd_path)
|
27
|
+
raise "Could not find the '#{cmd}' executable in PATH; add it to the PATH or specify its location using the '#{attr_names[0]}' document attribute" unless cmd_path
|
28
|
+
instance_variable_set(cmd_var, cmd_path)
|
29
|
+
end
|
30
|
+
cmd_path
|
11
31
|
end
|
12
|
-
nil
|
13
32
|
end
|
14
33
|
end
|
15
34
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'version'
|
3
|
+
|
4
|
+
Asciidoctor::Extensions.register do
|
5
|
+
require_relative 'wavedrom/extension'
|
6
|
+
|
7
|
+
block Asciidoctor::Diagram::WavedromBlockProcessor, :wavedrom
|
8
|
+
block_macro Asciidoctor::Diagram::WavedromBlockMacroProcessor, :wavedrom
|
9
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../extensions'
|
2
|
+
require_relative '../util/cli_generator'
|
3
|
+
require_relative '../util/which'
|
4
|
+
|
5
|
+
module Asciidoctor
|
6
|
+
module Diagram
|
7
|
+
# @private
|
8
|
+
module Wavedrom
|
9
|
+
include Which
|
10
|
+
|
11
|
+
def self.included(mod)
|
12
|
+
[:png, :svg].each do |f|
|
13
|
+
mod.register_format(f, :image) do |c, p|
|
14
|
+
if /darwin/ =~ RUBY_PLATFORM
|
15
|
+
wavedrom = which(p, 'WaveDromEditor.app', :attr_names => ['wavedrom'], :path => ['/Applications'])
|
16
|
+
if wavedrom
|
17
|
+
wavedrom = File.join(wavedrom, 'Contents/MacOS/nwjs')
|
18
|
+
end
|
19
|
+
else
|
20
|
+
wavedrom = which(p, 'WaveDromEditor', :attr_names => ['wavedrom'])
|
21
|
+
end
|
22
|
+
|
23
|
+
CliGenerator.generate_file(wavedrom, c.to_s) do |tool_path, input_path, output_path|
|
24
|
+
[tool_path, 'source', input_path, f.to_s, output_path]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class WavedromBlockProcessor < Extensions::DiagramBlockProcessor
|
32
|
+
include Wavedrom
|
33
|
+
end
|
34
|
+
|
35
|
+
class WavedromBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
|
36
|
+
include Wavedrom
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/blockdiag_spec.rb
CHANGED
data/spec/plantuml_spec.rb
CHANGED
@@ -485,4 +485,31 @@ A -> B
|
|
485
485
|
expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 1.5)
|
486
486
|
expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 1.5)
|
487
487
|
end
|
488
|
+
|
489
|
+
it "should handle embedded creole images correctly" do
|
490
|
+
creole_doc = <<-eos
|
491
|
+
= Hello, PlantUML!
|
492
|
+
Doc Writer <doc@example.com>
|
493
|
+
|
494
|
+
== First Section
|
495
|
+
|
496
|
+
[plantuml, format="png"]
|
497
|
+
----
|
498
|
+
:* You can change <color:red>text color</color>
|
499
|
+
* You can change <back:cadetblue>background color</back>
|
500
|
+
* You can change <size:18>size</size>
|
501
|
+
* You use <u>legacy</u> <b>HTML <i>tag</i></b>
|
502
|
+
* You use <u:red>color</u> <s:green>in HTML</s> <w:#0000FF>tag</w>
|
503
|
+
* Use image : <img:sourceforge.jpg>
|
504
|
+
* Use image : <img:http://www.foo.bar/sourceforge.jpg>
|
505
|
+
* Use image : <img:file:///sourceforge.jpg>
|
506
|
+
|
507
|
+
;
|
508
|
+
----
|
509
|
+
eos
|
510
|
+
|
511
|
+
Asciidoctor.load StringIO.new(creole_doc), :attributes => {'backend' => 'html5'}
|
512
|
+
|
513
|
+
# No real way to assert this since PlantUML doesn't produce an error on file not found
|
514
|
+
end
|
488
515
|
end
|
data/spec/shaape_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
-
describe Asciidoctor::Diagram::ShaapeBlockMacroProcessor do
|
3
|
+
describe Asciidoctor::Diagram::ShaapeBlockMacroProcessor, :broken => /darwin/ =~ RUBY_PLATFORM do
|
4
4
|
it "should generate PNG images when format is set to 'png'" do
|
5
5
|
code = <<-eos
|
6
6
|
+--------+ +-------------+
|
@@ -40,7 +40,7 @@ shaape::shaape.txt[format="png"]
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe Asciidoctor::Diagram::ShaapeBlockProcessor do
|
43
|
+
describe Asciidoctor::Diagram::ShaapeBlockProcessor, :broken => /darwin/ =~ RUBY_PLATFORM do
|
44
44
|
it "should generate PNG images when format is set to 'png'" do
|
45
45
|
doc = <<-eos
|
46
46
|
= Hello, Shaape!
|
@@ -159,6 +159,7 @@ shaape::shaape.txt
|
|
159
159
|
|
160
160
|
d = Asciidoctor.load StringIO.new(doc)
|
161
161
|
b = d.find { |b| b.context == :image }
|
162
|
+
expect(b).to_not be_nil
|
162
163
|
target = b.attributes['target']
|
163
164
|
mtime1 = File.mtime(target)
|
164
165
|
|
data/spec/test_helper.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative '../lib/asciidoctor-diagram/ditaa/extension'
|
|
11
11
|
require_relative '../lib/asciidoctor-diagram/graphviz/extension'
|
12
12
|
require_relative '../lib/asciidoctor-diagram/plantuml/extension'
|
13
13
|
require_relative '../lib/asciidoctor-diagram/shaape/extension'
|
14
|
+
require_relative '../lib/asciidoctor-diagram/wavedrom/extension'
|
14
15
|
|
15
16
|
module Asciidoctor
|
16
17
|
class AbstractBlock
|
@@ -30,6 +31,8 @@ module Asciidoctor
|
|
30
31
|
end
|
31
32
|
|
32
33
|
RSpec.configure do |c|
|
34
|
+
c.filter_run_excluding :broken => true
|
35
|
+
|
33
36
|
TEST_DIR = File.expand_path('testing')
|
34
37
|
|
35
38
|
c.before(:suite) do
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
code = <<-eos
|
4
|
+
{ signal : [
|
5
|
+
{ name: "clk", wave: "p......" },
|
6
|
+
{ name: "bus", wave: "x.34.5x", data: "head body tail" },
|
7
|
+
{ name: "wire", wave: "0.1..0." },
|
8
|
+
]}
|
9
|
+
eos
|
10
|
+
|
11
|
+
describe Asciidoctor::Diagram::WavedromBlockMacroProcessor, :broken => true do
|
12
|
+
it "should generate PNG images when format is set to 'png'" do
|
13
|
+
File.write('wavedrom.txt', code)
|
14
|
+
|
15
|
+
doc = <<-eos
|
16
|
+
= Hello, Wavedrom!
|
17
|
+
Doc Writer <doc@example.com>
|
18
|
+
|
19
|
+
== First Section
|
20
|
+
|
21
|
+
wavedrom::wavedrom.txt[format="png"]
|
22
|
+
eos
|
23
|
+
|
24
|
+
d = Asciidoctor.load StringIO.new(doc)
|
25
|
+
expect(d).to_not be_nil
|
26
|
+
|
27
|
+
b = d.find { |b| b.context == :image }
|
28
|
+
expect(b).to_not be_nil
|
29
|
+
|
30
|
+
expect(b.content_model).to eq :empty
|
31
|
+
|
32
|
+
target = b.attributes['target']
|
33
|
+
expect(target).to_not be_nil
|
34
|
+
expect(target).to match /\.png$/
|
35
|
+
expect(File.exists?(target)).to be true
|
36
|
+
|
37
|
+
expect(b.attributes['width']).to_not be_nil
|
38
|
+
expect(b.attributes['height']).to_not be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should generate SVG images when format is set to 'svg'" do
|
42
|
+
File.write('wavedrom.txt', code)
|
43
|
+
|
44
|
+
doc = <<-eos
|
45
|
+
= Hello, Wavedrom!
|
46
|
+
Doc Writer <doc@example.com>
|
47
|
+
|
48
|
+
== First Section
|
49
|
+
|
50
|
+
wavedrom::wavedrom.txt[format="svg"]
|
51
|
+
eos
|
52
|
+
|
53
|
+
d = Asciidoctor.load StringIO.new(doc)
|
54
|
+
expect(d).to_not be_nil
|
55
|
+
|
56
|
+
b = d.find { |b| b.context == :image }
|
57
|
+
expect(b).to_not be_nil
|
58
|
+
|
59
|
+
expect(b.content_model).to eq :empty
|
60
|
+
|
61
|
+
target = b.attributes['target']
|
62
|
+
expect(target).to_not be_nil
|
63
|
+
expect(target).to match /\.svg/
|
64
|
+
expect(File.exists?(target)).to be true
|
65
|
+
|
66
|
+
expect(b.attributes['width']).to_not be_nil
|
67
|
+
expect(b.attributes['height']).to_not be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Asciidoctor::Diagram::WavedromBlockProcessor, :broken => true do
|
72
|
+
it "should generate PNG images when format is set to 'png'" do
|
73
|
+
doc = <<-eos
|
74
|
+
= Hello, Wavedrom!
|
75
|
+
Doc Writer <doc@example.com>
|
76
|
+
|
77
|
+
== First Section
|
78
|
+
|
79
|
+
[wavedrom, format="png"]
|
80
|
+
----
|
81
|
+
#{code}
|
82
|
+
----
|
83
|
+
eos
|
84
|
+
|
85
|
+
d = Asciidoctor.load StringIO.new(doc)
|
86
|
+
expect(d).to_not be_nil
|
87
|
+
|
88
|
+
b = d.find { |b| b.context == :image }
|
89
|
+
expect(b).to_not be_nil
|
90
|
+
|
91
|
+
expect(b.content_model).to eq :empty
|
92
|
+
|
93
|
+
target = b.attributes['target']
|
94
|
+
expect(target).to_not be_nil
|
95
|
+
expect(target).to match /\.png$/
|
96
|
+
expect(File.exists?(target)).to be true
|
97
|
+
|
98
|
+
expect(b.attributes['width']).to_not be_nil
|
99
|
+
expect(b.attributes['height']).to_not be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should generate SVG images when format is set to 'svg'" do
|
103
|
+
doc = <<-eos
|
104
|
+
= Hello, Wavedrom!
|
105
|
+
Doc Writer <doc@example.com>
|
106
|
+
|
107
|
+
== First Section
|
108
|
+
|
109
|
+
[wavedrom, format="svg"]
|
110
|
+
----
|
111
|
+
#{code}
|
112
|
+
----
|
113
|
+
eos
|
114
|
+
|
115
|
+
d = Asciidoctor.load StringIO.new(doc)
|
116
|
+
expect(d).to_not be_nil
|
117
|
+
|
118
|
+
b = d.find { |b| b.context == :image }
|
119
|
+
expect(b).to_not be_nil
|
120
|
+
|
121
|
+
expect(b.content_model).to eq :empty
|
122
|
+
|
123
|
+
target = b.attributes['target']
|
124
|
+
expect(target).to_not be_nil
|
125
|
+
expect(target).to match /\.svg/
|
126
|
+
expect(File.exists?(target)).to be true
|
127
|
+
|
128
|
+
expect(b.attributes['width']).to_not be_nil
|
129
|
+
expect(b.attributes['height']).to_not be_nil
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should raise an error when when format is set to an invalid value" do
|
133
|
+
doc = <<-eos
|
134
|
+
= Hello, Wavedrom!
|
135
|
+
Doc Writer <doc@example.com>
|
136
|
+
|
137
|
+
== First Section
|
138
|
+
|
139
|
+
[wavedrom, format="foobar"]
|
140
|
+
----
|
141
|
+
----
|
142
|
+
eos
|
143
|
+
|
144
|
+
expect { Asciidoctor.load StringIO.new(doc) }.to raise_error /support.*format/i
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not regenerate images when source has not changed" do
|
148
|
+
File.write('wavedrom.txt', code)
|
149
|
+
|
150
|
+
doc = <<-eos
|
151
|
+
= Hello, Wavedrom!
|
152
|
+
Doc Writer <doc@example.com>
|
153
|
+
|
154
|
+
== First Section
|
155
|
+
|
156
|
+
wavedrom::wavedrom.txt
|
157
|
+
|
158
|
+
[wavedrom, format="png"]
|
159
|
+
----
|
160
|
+
#{code}
|
161
|
+
----
|
162
|
+
eos
|
163
|
+
|
164
|
+
d = Asciidoctor.load StringIO.new(doc)
|
165
|
+
b = d.find { |b| b.context == :image }
|
166
|
+
expect(b).to_not be_nil
|
167
|
+
target = b.attributes['target']
|
168
|
+
mtime1 = File.mtime(target)
|
169
|
+
|
170
|
+
sleep 1
|
171
|
+
|
172
|
+
d = Asciidoctor.load StringIO.new(doc)
|
173
|
+
|
174
|
+
mtime2 = File.mtime(target)
|
175
|
+
|
176
|
+
expect(mtime2).to eq mtime1
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should handle two block macros with the same source" do
|
180
|
+
File.write('wavedrom.txt', code)
|
181
|
+
|
182
|
+
doc = <<-eos
|
183
|
+
= Hello, Wavedrom!
|
184
|
+
Doc Writer <doc@example.com>
|
185
|
+
|
186
|
+
== First Section
|
187
|
+
|
188
|
+
wavedrom::wavedrom.txt[]
|
189
|
+
wavedrom::wavedrom.txt[]
|
190
|
+
eos
|
191
|
+
|
192
|
+
Asciidoctor.load StringIO.new(doc)
|
193
|
+
expect(File.exists?('wavedrom.png')).to be true
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should respect target attribute in block macros" do
|
197
|
+
File.write('wavedrom.txt', code)
|
198
|
+
|
199
|
+
doc = <<-eos
|
200
|
+
= Hello, Wavedrom!
|
201
|
+
Doc Writer <doc@example.com>
|
202
|
+
|
203
|
+
== First Section
|
204
|
+
|
205
|
+
wavedrom::wavedrom.txt["foobar"]
|
206
|
+
wavedrom::wavedrom.txt["foobaz"]
|
207
|
+
eos
|
208
|
+
|
209
|
+
Asciidoctor.load StringIO.new(doc)
|
210
|
+
expect(File.exists?('foobar.png')).to be true
|
211
|
+
expect(File.exists?('foobaz.png')).to be true
|
212
|
+
expect(File.exists?('wavedrom.png')).to be false
|
213
|
+
end
|
214
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-diagram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,7 +81,7 @@ files:
|
|
81
81
|
- examples/README.adoc
|
82
82
|
- examples/design.adoc
|
83
83
|
- examples/features.adoc
|
84
|
-
- lib/asciidoctor-diagram-java-1.3.
|
84
|
+
- lib/asciidoctor-diagram-java-1.3.7.jar
|
85
85
|
- lib/asciidoctor-diagram.rb
|
86
86
|
- lib/asciidoctor-diagram/blockdiag.rb
|
87
87
|
- lib/asciidoctor-diagram/blockdiag/extension.rb
|
@@ -104,6 +104,8 @@ files:
|
|
104
104
|
- lib/asciidoctor-diagram/util/svg.rb
|
105
105
|
- lib/asciidoctor-diagram/util/which.rb
|
106
106
|
- lib/asciidoctor-diagram/version.rb
|
107
|
+
- lib/asciidoctor-diagram/wavedrom.rb
|
108
|
+
- lib/asciidoctor-diagram/wavedrom/extension.rb
|
107
109
|
- lib/ditaamini-0.10.jar
|
108
110
|
- lib/plantuml.jar
|
109
111
|
- spec/blockdiag_spec.rb
|
@@ -112,6 +114,7 @@ files:
|
|
112
114
|
- spec/plantuml_spec.rb
|
113
115
|
- spec/shaape_spec.rb
|
114
116
|
- spec/test_helper.rb
|
117
|
+
- spec/wavedrom_spec.rb
|
115
118
|
homepage: https://github.com/asciidoctor/asciidoctor-diagram
|
116
119
|
licenses:
|
117
120
|
- MIT
|
@@ -144,4 +147,5 @@ test_files:
|
|
144
147
|
- spec/plantuml_spec.rb
|
145
148
|
- spec/shaape_spec.rb
|
146
149
|
- spec/test_helper.rb
|
150
|
+
- spec/wavedrom_spec.rb
|
147
151
|
has_rdoc:
|
Binary file
|