asciidoctor-diagram 1.1.5-java → 1.1.6-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +14 -0
- data/lib/asciidoctor-diagram.rb +3 -1
- data/lib/asciidoctor-diagram/blockdiag.rb +8 -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 +9 -32
- data/lib/asciidoctor-diagram/plantuml/extension.rb +12 -34
- data/lib/asciidoctor-diagram/plantuml/generator.rb +3 -13
- data/lib/asciidoctor-diagram/shaape.rb +8 -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 +61 -46
- 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 +23 -14
- 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: 09829992d77c04af14ead06c234d1bd419290c63
|
4
|
+
data.tar.gz: 35a0b6376b1546967d093fb1e26acefce3cb7c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0cc883aeeb61dad988639e95cdcb24cd7019d328c57dfdcc20078d07e9830078d0a5ffc292cdfaef9ad577c9ac1b0b6cbda0c8dc8b34fe33d100f2506548cea
|
7
|
+
data.tar.gz: 1a113811b3b33ba6529aba3973a9f2359544c07fcafebe9f58339b794beb16706dd82fdfb312f592a825e954c5a3e440b69cedfd22b7bcaaa175ce42171a3bec
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
= Asciidoctor-diagram Changelog
|
2
2
|
|
3
|
+
== 1.1.6
|
4
|
+
|
5
|
+
Enhancements::
|
6
|
+
|
7
|
+
* Updated PlantUML to revision 8002 (23/07U/2014)
|
8
|
+
* Add support for Shaape diagrams (requires Shaape to be installed separately)
|
9
|
+
* Add support for Blockdiag diagrams (requires Blockdiag to be installed separately)
|
10
|
+
* Add support for Actdiag diagrams (requires Actdiag to be installed separately)
|
11
|
+
* Add support for Seqdiag diagrams (requires Seqdiag to be installed separately)
|
12
|
+
* Add support for Nwdiag diagrams (requires Nwdiag to be installed separately)
|
13
|
+
|
14
|
+
Bug Fixes::
|
15
|
+
* Issue #38: Resolved Graphviz syntax errors with certain diagrams
|
16
|
+
|
3
17
|
== 1.1.5
|
4
18
|
|
5
19
|
Enhancements::
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'asciidoctor/extensions'
|
2
|
+
require_relative 'version'
|
3
|
+
|
4
|
+
Asciidoctor::Extensions.register do
|
5
|
+
require_relative 'blockdiag/extension'
|
6
|
+
block :blockdiag, Asciidoctor::Diagram::BlockDiagBlock
|
7
|
+
block_macro :blockdiag, Asciidoctor::Diagram::BlockDiagBlockMacro
|
8
|
+
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
|
+
DiagramProcessor.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(context, document, opts = {})
|
33
|
-
super
|
34
|
-
register_formats()
|
30
|
+
DiagramProcessor.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,18 @@
|
|
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
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
register_format(:svg, :image) do |c, p|
|
16
|
-
plantuml(p, c, 'dot', '-tsvg')
|
6
|
+
module Diagram
|
7
|
+
DiagramProcessor.define_processors('Graphviz') do
|
8
|
+
[:png, :svg].each do |f|
|
9
|
+
register_format(f, :image) do |c, p|
|
10
|
+
CliGenerator.generate('dot', p, c) do |tool_path, output_path|
|
11
|
+
[tool_path, "-o#{output_path}", "-T#{f.to_s}"]
|
12
|
+
end
|
13
|
+
end
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
20
|
-
|
21
|
-
class GraphvizBlock < Asciidoctor::Extensions::BlockProcessor
|
22
|
-
include DiagramProcessorBase
|
23
|
-
include GraphvizBase
|
24
|
-
|
25
|
-
def initialize(context, document, opts = {})
|
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(context, document, opts = {})
|
36
|
-
super
|
37
|
-
register_formats()
|
38
|
-
end
|
39
|
-
end
|
40
17
|
end
|
41
18
|
end
|
@@ -3,47 +3,25 @@ require_relative 'generator'
|
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def register_formats(document)
|
6
|
+
DiagramProcessor.define_processors('PlantUml') do
|
7
|
+
def config_args(parent)
|
12
8
|
config_args = []
|
13
|
-
config = document.attributes['plantumlconfig']
|
9
|
+
config = parent.document.attributes['plantumlconfig']
|
14
10
|
if config
|
15
|
-
config_args += ['-config', File.expand_path(config, document.attributes['docdir'])]
|
11
|
+
config_args += ['-config', File.expand_path(config, parent.document.attributes['docdir'])]
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
plantuml(p, c, 'uml', *config_args)
|
20
|
-
end
|
21
|
-
register_format(:svg, :image) do |c, p|
|
22
|
-
plantuml(p, c, 'uml', '-tsvg', *config_args)
|
23
|
-
end
|
24
|
-
register_format(:txt, :literal) do |c, p|
|
25
|
-
plantuml(p, c, 'uml', '-tutxt', *config_args)
|
26
|
-
end
|
14
|
+
config_args
|
27
15
|
end
|
28
|
-
end
|
29
16
|
|
30
|
-
|
31
|
-
|
32
|
-
include PlantUmlBase
|
33
|
-
|
34
|
-
def initialize(context, document, opts = {})
|
35
|
-
super
|
36
|
-
register_formats(document)
|
17
|
+
register_format(:png, :image) do |c, p|
|
18
|
+
PlantUmlGenerator.plantuml(p, c, 'uml', *config_args(p))
|
37
19
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def initialize(context, document, opts = {})
|
45
|
-
super
|
46
|
-
register_formats(document)
|
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))
|
47
25
|
end
|
48
26
|
end
|
49
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
|
|
@@ -35,17 +36,6 @@ module Asciidoctor
|
|
35
36
|
ps.close
|
36
37
|
Java.string_from_java_bytes(bos.toByteArray)
|
37
38
|
end
|
38
|
-
|
39
|
-
def which(cmd)
|
40
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
41
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
42
|
-
exts.each { |ext|
|
43
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
44
|
-
return exe if File.executable? exe
|
45
|
-
}
|
46
|
-
end
|
47
|
-
nil
|
48
|
-
end
|
49
39
|
end
|
50
40
|
end
|
51
41
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../util/cli_generator'
|
2
|
+
require_relative '../util/diagram'
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Diagram
|
6
|
+
DiagramProcessor.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,7 +8,7 @@ require_relative 'svg'
|
|
8
8
|
|
9
9
|
module Asciidoctor
|
10
10
|
module Diagram
|
11
|
-
module
|
11
|
+
module DiagramProcessor
|
12
12
|
IMAGE_PARAMS = {
|
13
13
|
:svg => {
|
14
14
|
:encoding => Encoding::UTF_8,
|
@@ -20,42 +20,81 @@ module Asciidoctor
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
module ClassMethods
|
24
|
+
#
|
25
|
+
# Registers a supported format. The first registered format becomes the default format for the block processor.
|
26
|
+
#
|
27
|
+
# +format+ is a symbol with the format name
|
28
|
+
# +type+ is a symbol and should be either :image or :literal
|
29
|
+
# +block+ is a block that produces the diagrams from code. The block receives the parent asciidoc block and the diagram code as arguments
|
30
|
+
#
|
31
|
+
def register_format(format, type, &block)
|
32
|
+
unless @default_format
|
33
|
+
@default_format = format
|
34
|
+
end
|
25
35
|
|
26
|
-
|
27
|
-
|
28
|
-
|
36
|
+
formats[format] = {
|
37
|
+
:type => type,
|
38
|
+
:generator => block
|
39
|
+
}
|
40
|
+
end
|
29
41
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
else
|
34
|
-
base.instance_eval do
|
35
|
-
alias_method :process, :process_macro
|
36
|
-
end
|
42
|
+
def formats
|
43
|
+
@formats ||= {}
|
37
44
|
end
|
38
45
|
|
46
|
+
def default_format
|
47
|
+
@default_format
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
|
-
def
|
42
|
-
|
43
|
-
attributes['target'] ||= File.basename(target, File.extname(target))
|
44
|
-
|
45
|
-
generate_block(parent, source, attributes)
|
51
|
+
def self.included base
|
52
|
+
base.extend ClassMethods
|
46
53
|
end
|
47
54
|
|
48
|
-
def
|
49
|
-
|
55
|
+
def self.define_processors(name, &init)
|
56
|
+
block = Class.new(Asciidoctor::Extensions::BlockProcessor) do
|
57
|
+
include DiagramProcessor
|
58
|
+
|
59
|
+
option :pos_attrs, ['target', 'format']
|
60
|
+
option :contexts, [:listing, :literal, :open]
|
61
|
+
option :content_model, :simple
|
62
|
+
|
63
|
+
def process(parent, reader, attributes)
|
64
|
+
generate_block(parent, ReaderSource.new(reader), attributes)
|
65
|
+
end
|
66
|
+
|
67
|
+
self.instance_eval &init
|
68
|
+
end
|
69
|
+
|
70
|
+
block_macro = Class.new(Asciidoctor::Extensions::BlockMacroProcessor) do
|
71
|
+
include DiagramProcessor
|
72
|
+
|
73
|
+
option :pos_attrs, ['target', 'format']
|
74
|
+
|
75
|
+
def process(parent, target, attributes)
|
76
|
+
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
77
|
+
attributes['target'] ||= File.basename(target, File.extname(target))
|
78
|
+
|
79
|
+
generate_block(parent, source, attributes)
|
80
|
+
end
|
81
|
+
|
82
|
+
self.instance_eval &init
|
83
|
+
end
|
84
|
+
|
85
|
+
Asciidoctor::Diagram.const_set("#{name}Block", block)
|
86
|
+
Asciidoctor::Diagram.const_set("#{name}BlockMacro", block_macro)
|
50
87
|
end
|
51
88
|
|
89
|
+
private
|
90
|
+
|
52
91
|
def generate_block(parent, source, attributes)
|
53
|
-
format = attributes.delete('format') ||
|
92
|
+
format = attributes.delete('format') || self.class.default_format
|
54
93
|
format = format.to_sym if format.respond_to?(:to_sym)
|
55
94
|
|
56
95
|
raise "Format undefined" unless format
|
57
96
|
|
58
|
-
generator_info = formats[format]
|
97
|
+
generator_info = self.class.formats[format]
|
59
98
|
|
60
99
|
raise "#{self.class.name} does not support output format #{format}" unless generator_info
|
61
100
|
|
@@ -69,30 +108,6 @@ module Asciidoctor
|
|
69
108
|
end
|
70
109
|
end
|
71
110
|
|
72
|
-
private
|
73
|
-
|
74
|
-
#
|
75
|
-
# Registers a supported format. The first registered format becomes the default format for the block processor.
|
76
|
-
#
|
77
|
-
# +format+ is a symbol with the format name
|
78
|
-
# +type+ is a symbol and should be either :image or :literal
|
79
|
-
# +block+ is a block that produces the diagrams from code. The block receives the parent asciidoc block and the diagram code as arguments
|
80
|
-
#
|
81
|
-
def register_format(format, type, &block)
|
82
|
-
unless @default_format
|
83
|
-
@default_format = format
|
84
|
-
end
|
85
|
-
|
86
|
-
formats[format] = {
|
87
|
-
:type => type,
|
88
|
-
:generator => block
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
def formats
|
93
|
-
@formats ||= {}
|
94
|
-
end
|
95
|
-
|
96
111
|
def create_image_block(parent, source, attributes, format, generator_info)
|
97
112
|
target = attributes.delete('target')
|
98
113
|
|