asciidoctor-diagram 1.2.0.preview.5-java → 1.2.1-java
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 +4 -4
- data/CHANGELOG.adoc +17 -0
- data/lib/asciidoctor-diagram.rb +3 -1
- data/lib/asciidoctor-diagram/blockdiag.rb +15 -0
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +18 -0
- data/lib/asciidoctor-diagram/ditaa/extension.rb +21 -23
- data/lib/asciidoctor-diagram/graphviz/extension.rb +7 -32
- data/lib/asciidoctor-diagram/plantuml/extension.rb +15 -31
- data/lib/asciidoctor-diagram/plantuml/generator.rb +3 -13
- data/lib/asciidoctor-diagram/shaape.rb +9 -0
- data/lib/asciidoctor-diagram/shaape/extension.rb +16 -0
- data/lib/asciidoctor-diagram/util/cli_generator.rb +40 -0
- data/lib/asciidoctor-diagram/util/diagram.rb +67 -50
- data/lib/asciidoctor-diagram/util/svg.rb +19 -23
- data/lib/asciidoctor-diagram/util/which.rb +14 -0
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/plantuml.jar +0 -0
- data/spec/blockdiag_spec.rb +183 -0
- data/spec/ditaa_spec.rb +3 -3
- data/spec/graphviz_spec.rb +28 -3
- data/spec/plantuml_spec.rb +11 -11
- data/spec/shaape_spec.rb +227 -0
- data/spec/test_helper.rb +2 -0
- metadata +26 -17
- data/lib/asciidoctor-diagram/ditaa/generator.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd129d7f1a3bcb983c175ff81f7278736e8f84f
|
4
|
+
data.tar.gz: fbd0f23226b3dd0df2b648e7b69a3c4721a3a4e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6b8951de8298832807be2187d14894194d92a0f61467dbc5d53ec2d9e6f2f7dd1f13bb00d5c63e66f82dc5a09eee65710f4619cb3acc93e9be97ad07330c2d0
|
7
|
+
data.tar.gz: 3431ef61b193d3029a657bdec8955c9062ab7cf25f8c49533d40ca3006e338e90a85605d80177563ecaae0140c503791aac9f533b9a393bd2732a860d443ebbb
|
data/CHANGELOG.adoc
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
= Asciidoctor-diagram Changelog
|
2
2
|
|
3
|
+
== 1.2.1
|
4
|
+
|
5
|
+
Enhancements::
|
6
|
+
|
7
|
+
* Add support for Actdiag, Seqdiag, Nwdiag, Packetdiag and Rackdiag diagrams (requires resp. Python packages to be installed separately)
|
8
|
+
|
3
9
|
== 1.2.0
|
4
10
|
|
5
11
|
Enhancements::
|
6
12
|
|
7
13
|
* Updated to Asciidoctor 1.5.0
|
8
14
|
|
15
|
+
== 1.1.6
|
16
|
+
|
17
|
+
Enhancements::
|
18
|
+
|
19
|
+
* Updated PlantUML to revision 8002 (23/07U/2014)
|
20
|
+
* Add support for Shaape diagrams (requires Shaape Python package to be installed separately)
|
21
|
+
* Add support for Blockdiag diagrams (requires Blockdiag Python package to be installed separately)
|
22
|
+
|
23
|
+
Bug Fixes::
|
24
|
+
* Issue #38: Resolved Graphviz syntax errors with certain diagrams
|
25
|
+
|
9
26
|
== 1.1.5
|
10
27
|
|
11
28
|
Enhancements::
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'version'
|
3
|
+
|
4
|
+
Asciidoctor::Extensions.register do
|
5
|
+
require_relative 'blockdiag/extension'
|
6
|
+
|
7
|
+
['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
|
8
|
+
name = tool.downcase.to_sym
|
9
|
+
block = Asciidoctor::Diagram.const_get("#{tool}Block")
|
10
|
+
block_macro = Asciidoctor::Diagram.const_get("#{tool}BlockMacro")
|
11
|
+
|
12
|
+
block block, name
|
13
|
+
block_macro block_macro, name
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../util/cli_generator'
|
2
|
+
require_relative '../util/diagram'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
['BlockDiag', 'SeqDiag', 'ActDiag', 'NwDiag', 'RackDiag', 'PacketDiag'].each do |tool|
|
7
|
+
define_processors(tool) do
|
8
|
+
[:png, :svg].each do |f|
|
9
|
+
register_format(f, :image) do |c, p|
|
10
|
+
CliGenerator.generate(tool.downcase, p, c) do |tool_path, output_path|
|
11
|
+
[tool_path, '-o', output_path, "-T#{f.to_s}", '-']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,37 +1,35 @@
|
|
1
1
|
require_relative '../util/diagram'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../util/java'
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
module
|
7
|
-
|
6
|
+
module DitaaGenerator
|
7
|
+
DITAA_JAR_PATH = File.expand_path File.join('../..', 'ditaamini0_9.jar'), File.dirname(__FILE__)
|
8
|
+
Java.classpath << DITAA_JAR_PATH
|
8
9
|
|
9
|
-
|
10
|
+
def self.ditaa(code)
|
11
|
+
Java.load
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
args = ['-e', 'UTF-8']
|
14
|
+
|
15
|
+
bytes = code.encode(Encoding::UTF_8).bytes.to_a
|
16
|
+
bis = Java.new_object(Java.java.io.ByteArrayInputStream, '[B', Java.array_to_java_array(bytes, :byte))
|
17
|
+
bos = Java.new_object(Java.java.io.ByteArrayOutputStream)
|
18
|
+
result_code = Java.org.stathissideris.ascii2image.core.CommandLineConverter.convert(Java.array_to_java_array(args, :string), bis, bos)
|
19
|
+
bis.close
|
20
|
+
bos.close
|
17
21
|
|
18
|
-
|
19
|
-
include DiagramProcessorBase
|
20
|
-
include DitaaBase
|
22
|
+
result = Java.string_from_java_bytes(bos.toByteArray)
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
raise "Ditaa image generation failed: #{result}" unless result_code == 0
|
25
|
+
|
26
|
+
result
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def initialize name = nil, config = {}
|
33
|
-
super
|
34
|
-
register_formats()
|
30
|
+
define_processors('Ditaa') do
|
31
|
+
register_format(:png, :image) do |c|
|
32
|
+
DitaaGenerator.ditaa(c)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -1,41 +1,16 @@
|
|
1
|
+
require_relative '../util/cli_generator'
|
1
2
|
require_relative '../util/diagram'
|
2
|
-
require_relative '../plantuml/generator'
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
register_format(:png, :image) do |c, p|
|
13
|
-
plantuml(p, c, 'dot')
|
14
|
-
end
|
15
|
-
register_format(:svg, :image) do |c, p|
|
16
|
-
plantuml(p, c, 'dot', '-tsvg')
|
6
|
+
define_processors('Graphviz') do
|
7
|
+
[:png, :svg].each do |f|
|
8
|
+
register_format(f, :image) do |c, p|
|
9
|
+
CliGenerator.generate('dot', p, c) do |tool_path, output_path|
|
10
|
+
[tool_path, "-o#{output_path}", "-T#{f.to_s}"]
|
11
|
+
end
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
20
|
-
|
21
|
-
class GraphvizBlock < Asciidoctor::Extensions::BlockProcessor
|
22
|
-
include DiagramProcessorBase
|
23
|
-
include GraphvizBase
|
24
|
-
|
25
|
-
def initialize name = nil, config = {}
|
26
|
-
super
|
27
|
-
register_formats()
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class GraphvizBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
32
|
-
include DiagramProcessorBase
|
33
|
-
include GraphvizBase
|
34
|
-
|
35
|
-
def initialize name = nil, config = {}
|
36
|
-
super
|
37
|
-
register_formats()
|
38
|
-
end
|
39
|
-
end
|
40
15
|
end
|
41
16
|
end
|
@@ -3,41 +3,25 @@ require_relative 'generator'
|
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
register_format(:png, :image) do |c, p|
|
13
|
-
plantuml(p, c, 'uml')
|
14
|
-
end
|
15
|
-
register_format(:svg, :image) do |c, p|
|
16
|
-
plantuml(p, c, 'uml', '-tsvg')
|
6
|
+
define_processors('PlantUml') do
|
7
|
+
def config_args(parent)
|
8
|
+
config_args = []
|
9
|
+
config = parent.document.attributes['plantumlconfig']
|
10
|
+
if config
|
11
|
+
config_args += ['-config', File.expand_path(config, parent.document.attributes['docdir'])]
|
17
12
|
end
|
18
|
-
register_format(:txt, :literal) do |c, p|
|
19
|
-
plantuml(p, c, 'uml', '-tutxt')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
13
|
|
24
|
-
|
25
|
-
include DiagramProcessorBase
|
26
|
-
include PlantUmlBase
|
27
|
-
|
28
|
-
def initialize name = nil, config = {}
|
29
|
-
super
|
30
|
-
register_formats()
|
14
|
+
config_args
|
31
15
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class PlantUmlBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
35
|
-
include DiagramProcessorBase
|
36
|
-
include PlantUmlBase
|
37
16
|
|
38
|
-
|
39
|
-
|
40
|
-
|
17
|
+
register_format(:png, :image) do |c, p|
|
18
|
+
PlantUmlGenerator.plantuml(p, c, 'uml', *config_args(p))
|
19
|
+
end
|
20
|
+
register_format(:svg, :image) do |c, p|
|
21
|
+
PlantUmlGenerator.plantuml(p, c, 'uml', '-tsvg', *config_args(p))
|
22
|
+
end
|
23
|
+
register_format(:txt, :literal) do |c, p|
|
24
|
+
PlantUmlGenerator.plantuml(p, c, 'uml', '-tutxt', *config_args(p))
|
41
25
|
end
|
42
26
|
end
|
43
27
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../util/java'
|
2
|
+
require_relative '../util/which'
|
2
3
|
|
3
4
|
module Asciidoctor
|
4
5
|
module Diagram
|
@@ -8,10 +9,10 @@ module Asciidoctor
|
|
8
9
|
PLANTUML_JAR_PATH = File.expand_path File.join('../..', 'plantuml.jar'), File.dirname(__FILE__)
|
9
10
|
Java.classpath << PLANTUML_JAR_PATH
|
10
11
|
|
11
|
-
def plantuml(parent, code, tag, *flags)
|
12
|
+
def self.plantuml(parent, code, tag, *flags)
|
12
13
|
unless @graphvizdot
|
13
14
|
@graphvizdot = parent.document.attributes['graphvizdot']
|
14
|
-
@graphvizdot = which('dot') unless @graphvizdot && File.executable?(@graphvizdot)
|
15
|
+
@graphvizdot = ::Asciidoctor::Diagram.which('dot') unless @graphvizdot && File.executable?(@graphvizdot)
|
15
16
|
raise "Could not find the Graphviz 'dot' executable in PATH; add it to the PATH or specify its location using the 'graphvizdot' document attribute" unless @graphvizdot
|
16
17
|
end
|
17
18
|
|
@@ -40,17 +41,6 @@ module Asciidoctor
|
|
40
41
|
ps.close
|
41
42
|
Java.string_from_java_bytes(bos.toByteArray)
|
42
43
|
end
|
43
|
-
|
44
|
-
def which(cmd)
|
45
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
46
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
47
|
-
exts.each { |ext|
|
48
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
49
|
-
return exe if File.executable? exe
|
50
|
-
}
|
51
|
-
end
|
52
|
-
nil
|
53
|
-
end
|
54
44
|
end
|
55
45
|
end
|
56
46
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../util/cli_generator'
|
2
|
+
require_relative '../util/diagram'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
define_processors('Shaape') do
|
7
|
+
[:png, :svg].each do |f|
|
8
|
+
register_format(f, :image) do |c, p|
|
9
|
+
CliGenerator.generate('shaape', p, c) do |tool_path, output_path|
|
10
|
+
[tool_path, '-o', output_path, '-t', f.to_s, '-']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
require_relative '../util/java'
|
4
|
+
require_relative '../util/which'
|
5
|
+
|
6
|
+
module Asciidoctor
|
7
|
+
module Diagram
|
8
|
+
module CliGenerator
|
9
|
+
def self.generate(tool, parent, code)
|
10
|
+
tool_var = '@' + tool
|
11
|
+
|
12
|
+
tool_path = instance_variable_get(tool_var)
|
13
|
+
unless tool_path
|
14
|
+
tool_path = parent.document.attributes[tool]
|
15
|
+
tool_path = ::Asciidoctor::Diagram.which(tool) unless tool_path && File.executable?(tool_path)
|
16
|
+
raise "Could not find the '#{tool}' executable in PATH; add it to the PATH or specify its location using the 'shaape' document attribute" unless tool_path
|
17
|
+
instance_variable_set(tool_var, tool_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
target_file = Tempfile.new(tool)
|
21
|
+
begin
|
22
|
+
target_file.close
|
23
|
+
|
24
|
+
args = yield tool_path, target_file.path
|
25
|
+
|
26
|
+
IO.popen(args, "w") do |io|
|
27
|
+
io.write code
|
28
|
+
end
|
29
|
+
result_code = $?
|
30
|
+
|
31
|
+
raise "#{tool} image generation failed" unless result_code == 0
|
32
|
+
|
33
|
+
File.read(target_file.path)
|
34
|
+
ensure
|
35
|
+
target_file.unlink
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -8,69 +8,47 @@ require_relative 'svg'
|
|
8
8
|
|
9
9
|
module Asciidoctor
|
10
10
|
module Diagram
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:decoder => SVG
|
16
|
-
},
|
17
|
-
:png => {
|
18
|
-
:encoding => Encoding::ASCII_8BIT,
|
19
|
-
:decoder => PNG
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
def self.included(base)
|
24
|
-
base.option :pos_attrs, ['target', 'format']
|
25
|
-
|
26
|
-
if base.ancestors.include?(Asciidoctor::Extensions::BlockProcessor)
|
27
|
-
base.option :contexts, [:listing, :literal, :open]
|
28
|
-
base.option :content_model, :simple
|
29
|
-
|
30
|
-
base.instance_eval do
|
31
|
-
alias_method :process, :process_block
|
32
|
-
end
|
33
|
-
else
|
34
|
-
base.instance_eval do
|
35
|
-
alias_method :process, :process_macro
|
36
|
-
end
|
11
|
+
def self.define_processors(name, &init)
|
12
|
+
block = Class.new(Asciidoctor::Extensions::BlockProcessor) do
|
13
|
+
class << self
|
14
|
+
include FormatRegistry
|
37
15
|
end
|
16
|
+
include DiagramProcessor
|
38
17
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
43
|
-
attributes['target'] ||= File.basename(target, File.extname(target))
|
18
|
+
option :pos_attrs, ['target', 'format']
|
19
|
+
option :contexts, [:listing, :literal, :open]
|
20
|
+
option :content_model, :simple
|
44
21
|
|
45
|
-
|
46
|
-
|
22
|
+
def process(parent, reader, attributes)
|
23
|
+
generate_block(parent, ReaderSource.new(reader), attributes)
|
24
|
+
end
|
47
25
|
|
48
|
-
|
49
|
-
generate_block(parent, ReaderSource.new(reader), attributes)
|
26
|
+
self.instance_eval &init
|
50
27
|
end
|
51
28
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
29
|
+
block_macro = Class.new(Asciidoctor::Extensions::BlockMacroProcessor) do
|
30
|
+
class << self
|
31
|
+
include FormatRegistry
|
32
|
+
end
|
33
|
+
include DiagramProcessor
|
57
34
|
|
58
|
-
|
35
|
+
option :pos_attrs, ['target', 'format']
|
59
36
|
|
60
|
-
|
37
|
+
def process(parent, target, attributes)
|
38
|
+
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
39
|
+
attributes['target'] ||= File.basename(target, File.extname(target))
|
61
40
|
|
62
|
-
|
63
|
-
when :image
|
64
|
-
create_image_block(parent, source, attributes, format, generator_info)
|
65
|
-
when :literal
|
66
|
-
create_literal_block(parent, source, attributes, generator_info)
|
67
|
-
else
|
68
|
-
raise "Unsupported output format: #{format}"
|
41
|
+
generate_block(parent, source, attributes)
|
69
42
|
end
|
43
|
+
|
44
|
+
self.instance_eval &init
|
70
45
|
end
|
71
46
|
|
72
|
-
|
47
|
+
Asciidoctor::Diagram.const_set("#{name}Block", block)
|
48
|
+
Asciidoctor::Diagram.const_set("#{name}BlockMacro", block_macro)
|
49
|
+
end
|
73
50
|
|
51
|
+
module FormatRegistry
|
74
52
|
#
|
75
53
|
# Registers a supported format. The first registered format becomes the default format for the block processor.
|
76
54
|
#
|
@@ -93,6 +71,45 @@ module Asciidoctor
|
|
93
71
|
@formats ||= {}
|
94
72
|
end
|
95
73
|
|
74
|
+
def default_format
|
75
|
+
@default_format
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module DiagramProcessor
|
80
|
+
IMAGE_PARAMS = {
|
81
|
+
:svg => {
|
82
|
+
:encoding => Encoding::UTF_8,
|
83
|
+
:decoder => SVG
|
84
|
+
},
|
85
|
+
:png => {
|
86
|
+
:encoding => Encoding::ASCII_8BIT,
|
87
|
+
:decoder => PNG
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def generate_block(parent, source, attributes)
|
94
|
+
format = attributes.delete('format') || self.class.default_format
|
95
|
+
format = format.to_sym if format.respond_to?(:to_sym)
|
96
|
+
|
97
|
+
raise "Format undefined" unless format
|
98
|
+
|
99
|
+
generator_info = self.class.formats[format]
|
100
|
+
|
101
|
+
raise "#{self.class.name} does not support output format #{format}" unless generator_info
|
102
|
+
|
103
|
+
case generator_info[:type]
|
104
|
+
when :image
|
105
|
+
create_image_block(parent, source, attributes, format, generator_info)
|
106
|
+
when :literal
|
107
|
+
create_literal_block(parent, source, attributes, generator_info)
|
108
|
+
else
|
109
|
+
raise "Unsupported output format: #{format}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
96
113
|
def create_image_block(parent, source, attributes, format, generator_info)
|
97
114
|
target = attributes.delete('target')
|
98
115
|
|